- Home /
Problems with Photon self-hosted server
So I am trying to set up a self-hosted server for a project I am doing. Currently I have the settings in the Unity inspector as set to self-hosted, the server IP is set to my local IP and the port is set to 5055, the Appid is entered,and the RunInBackGround checkbox is checked as well as the AutoJoinLobby client setting checkbox. In the Photon Control I have the Game Server IP set to Autodetect public. On my network I have a static public IP facing toward the WAN and in my LAN I have set up a static local IP so the IP never changes for my computer on my local network or on the outside internet. I have set up the router to forward traffic from port 5055 to port 5057 all to my local IP address. (since the IP is static from the ISP the IP really lives on the router and you don't forward to a public IP but to a local one) The firewall is configured to let traffic through for those ports as well. I am using the Unity SDK version of Photon Server which has two folders that are named MasterServer and GameServer, in both of these folders I opened the Photon.LoadBalancing.dll.config files and modified the value for the MasterIPAddress so that is reads to my static public IP. In the MasterServer file this was line 147 and in the GameServer file it was line 141. Now I have a script that is attached to a gameobject in my project that persists from the start to the main scene. I am currently using the ConnectWithSettings, and the JoinOrCreateRoom. My problem is that when I load into the main scene I can tell that OnJoinRoom is not being called because i have several prefabs that are supposed to instantiate when you load into the room. Below is my code and the console from when you load into the main scene. Any help with this would be very much appreciated. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Photon; using Dissonance;
public class Connect : Photon.PunBehaviour {
public Dropdown genderDropDown;
public InputField roomName;
private string room;
private int playerCount = 0;
private PhotonView masterView;
private string _textMessage = "";
private readonly List<string> _textLog = new List<string>();
private int _count;
private RoomOptions roomOptions;
private TypedLobby PGS;
private string address = "NOT_SHOWING_IN_EXAMPLE";
private int port = 5505;
private string appID = "42aa30ee-f094-4aa1-bdd0-e74ed652592c";
private string gameVersion = "v.1";
//status indicator for connection
// ReSharper disable once UnusedMember.Local (Justification: Used implicitly by unity)
private void OnGUI()
{
GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
if (PhotonNetwork.isMasterClient)
GUILayout.Label(PhotonNetwork.connectionStateDetailed + " (Master Client)");
else
GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
if (PhotonNetwork.room != null)
GUILayout.Label("Room: " + PhotonNetwork.room.Name);
GUILayout.Label(PhotonNetwork.NetworkStatisticsToString());
GUILayout.Label("Photon Players:");
foreach (var player in PhotonNetwork.playerList)
{
if (player.IsLocal)
GUILayout.Label("> '" + player.ID + "' (Local)");
else
GUILayout.Label("> '" + player.ID + "'");
}
GUILayout.Label("Dissonance Players:");
var comms = FindObjectOfType<DissonanceComms>();
if (comms == null)
{
while (comms == null)
{
return;
}
}
if (comms.isActiveAndEnabled)
{
foreach (var player in comms.Players)
{
if (!player.IsConnected)
continue;
if (player.Name == comms.LocalPlayerName)
GUILayout.Label("> '" + player.Name + "' (Local)");
else
GUILayout.Label("> '" + player.Name + "' Speaking:" + player.IsSpeaking);
}
GUILayout.Space(25);
GUILayout.Label("Chat: ");
_textMessage = GUILayout.TextField(_textMessage);
if (GUILayout.Button("Send"))
{
comms.Text.Send("Global", _textMessage);
_textMessage = "";
}
for (int i = 0; i < Mathf.Min(10, _textLog.Count); i++)
{
GUILayout.Label(_textLog[_textLog.Count - 1 - i]);
}
}
}
// Automatically connect to the acting server
void Start()
{
//bool connectToMaster = PhotonNetwork.ConnectToMaster(address, port, appID, gameVersion);
PhotonNetwork.networkingPeer.SentCountAllowance = 15;
PhotonNetwork.ConnectUsingSettings("LEAVE_THIS_ALONE");
PhotonNetwork.automaticallySyncScene = true;
DontDestroyOnLoad(gameObject);
Debug.Log("Connecting to server...");
PhotonNetwork.NetworkStatisticsEnabled = true;
//PhotonNetwork.JoinLobby(PGS);
}
//Automatic Photon Call
public override void OnConnectedToPhoton()
{
Debug.Log("Connected to server");
Debug.Log("Server IP: " + PhotonNetwork.ServerAddress);
}
public override void OnConnectionFail(DisconnectCause cause)
{
Debug.Log("Failed to connect to server");
Debug.Log("Cause seems to be: " + cause);
}
//Called when either host or join button is pushed in the start scene
public void JoinOrHostRoom()
{
room = roomName.text;
if (room == "" || room == null)
{
room = "room1";
}
bool iscreated = PhotonNetwork.JoinOrCreateRoom(room,roomOptions,PGS);
PhotonNetwork.LoadLevel("Main");
PhotonNetwork.automaticallySyncScene = true;
Debug.Log("Created Room");
Debug.Log("iscreated:" + iscreated);
}
//Automatic Photon Call
public override void OnJoinedLobby()
{
Debug.Log("Joined Lobby");
}
//Called when a room is created
public override void OnCreatedRoom()
{
Debug.Log("Room Created: " + PhotonNetwork.room.Name);
}
//Called when a room is joined
public override void OnJoinedRoom()
{
if (PhotonNetwork.room != null)
{
Debug.Log("Connected to room: " + PhotonNetwork.room.Name);
playerCount += 1;
}
else
{
Debug.Log("Not in a room.");
}
Debug.Log("Player count is: " + playerCount);
PlayerSpawn();
var comms = FindObjectOfType<DissonanceComms>();
comms.Rooms.Join("Global");
comms.Text.MessageReceived += (msg) => { _textLog.Add(msg.Sender + " Says > " + msg.Message); };
}
//Photon Read Automatic Fallback
public void OnPhotonRandomJoinFailed()
{
room = roomName.text;
if (room == "" || room == null)
{
room = "room1";
}
Debug.Log("Failed to find room, creating host");
PhotonNetwork.automaticallySyncScene = true;
PhotonNetwork.CreateRoom(room);
PhotonNetwork.LoadLevel("Main");
}
//Spawn a player prefab based on the gender selected in the dropdown
public void PlayerSpawn()
{
if (genderDropDown.value == 1)
{
PhotonNetwork.Instantiate("MaleVRPlayer", ViveManager.instance.head.transform.position, ViveManager.instance.head.transform.rotation, 0);
PhotonNetwork.Instantiate("leftHand", ViveManager.instance.leftHand.transform.position, ViveManager.instance.leftHand.transform.rotation, 0);
PhotonNetwork.Instantiate("rightHand", ViveManager.instance.rightHand.transform.position, ViveManager.instance.rightHand.transform.rotation, 0);
}
if (genderDropDown.value == 2)
{
PhotonNetwork.Instantiate("FemaleVRPlayer", ViveManager.instance.head.transform.position, ViveManager.instance.head.transform.rotation, 0);
PhotonNetwork.Instantiate("leftHand", ViveManager.instance.leftHand.transform.position, ViveManager.instance.leftHand.transform.rotation, 0);
PhotonNetwork.Instantiate("rightHand", ViveManager.instance.rightHand.transform.position, ViveManager.instance.rightHand.transform.rotation, 0);
}
if (genderDropDown.value == 0)
{
PhotonNetwork.Instantiate("MaleVRPlayer", ViveManager.instance.head.transform.position, ViveManager.instance.head.transform.rotation, 0);
PhotonNetwork.Instantiate("leftHand", ViveManager.instance.leftHand.transform.position, ViveManager.instance.leftHand.transform.rotation, 0);
PhotonNetwork.Instantiate("rightHand", ViveManager.instance.rightHand.transform.position, ViveManager.instance.rightHand.transform.rotation, 0);
}
}
}
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Remote database for leaderboard 2 Answers
Using lerp to smooth network movement causes rubber banding 1 Answer
Only do something if it has the same tag as the player 2 Answers
Photon - Hide/Show Object 1 Answer