|
|
@ -46,7 +46,7 @@ namespace Networking.Server |
|
|
|
#endregion Public Variables
|
|
|
|
|
|
|
|
#region Private Variables
|
|
|
|
public NetworkServerSimple server; |
|
|
|
public ServerObject server; |
|
|
|
#endregion Private Variables
|
|
|
|
|
|
|
|
|
|
|
@ -66,7 +66,7 @@ namespace Networking.Server |
|
|
|
/// <param name="serverObject">Server to register handlers with</param>
|
|
|
|
public void SetUp(ServerObject serverObject) |
|
|
|
{ |
|
|
|
this.server = serverObject.server; |
|
|
|
this.server = serverObject; |
|
|
|
Reset(); |
|
|
|
server.RegisterHandler(MsgType.Connect, OnClientConnect); |
|
|
|
server.RegisterHandler(MsgType.Disconnect, OnClientDisconnect); |
|
|
@ -75,6 +75,9 @@ namespace Networking.Server |
|
|
|
|
|
|
|
public void OnClientConnect(NetworkMessage msg) |
|
|
|
{ |
|
|
|
|
|
|
|
Debug.Log("newClient: " + msg.conn.address + ", " + msg.conn.Hash() + ", " + msg.conn.hostId); |
|
|
|
|
|
|
|
if (ConnectedClients.Any(p => p.ID == msg.channelId)) |
|
|
|
{ |
|
|
|
Debug.LogError("Client[" + msg.channelId + "] already connected"); |
|
|
@ -93,13 +96,13 @@ namespace Networking.Server |
|
|
|
{ |
|
|
|
PotentialClients.RemoveAll(p => p == msg.conn); |
|
|
|
|
|
|
|
if (!ConnectedClients.Any(p => p.ID == msg.conn.connectionId)) |
|
|
|
if (!ConnectedClients.Any(p => p.ID == msg.conn.Hash())) |
|
|
|
{ |
|
|
|
Debug.LogError("Unknown client disconnect [" + msg.conn.connectionId + "]"); |
|
|
|
Debug.LogError("Unknown client disconnect [" + msg.conn.Hash() + "]"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
ClientData client = ConnectedClients.FirstOrDefault(p => p.ID == msg.conn.connectionId); |
|
|
|
ClientData client = ConnectedClients.FirstOrDefault(p => p.ID == msg.conn.Hash()); |
|
|
|
ConnectedClients.Remove(client); |
|
|
|
DisconnectedClients.Add(client); |
|
|
|
|
|
|
@ -119,14 +122,16 @@ namespace Networking.Server |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (ConnectedClients.Any(p => p.ID == msg.channelId)) |
|
|
|
|
|
|
|
|
|
|
|
if (ConnectedClients.Any(p => p.ID == msg.conn.Hash())) |
|
|
|
{ |
|
|
|
Debug.LogError("Client[" + msg.channelId + "] already connected"); |
|
|
|
msg.conn.Send(LoginProtocols.LoginFail, new LoginProtocols.EmptyMsg()); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
ClientData newClient = DisconnectedClients.FirstOrDefault(p => p.ID == msg.conn.connectionId); |
|
|
|
ClientData newClient = DisconnectedClients.FirstOrDefault(p => p.ID == msg.conn.Hash()); |
|
|
|
if (newClient != default) |
|
|
|
{ |
|
|
|
Debug.Log("Reconnection: " + loginMsg.Name + ((loginMsg.Name != newClient.Name) ? (" (Prev. " + newClient.Name +")") : "")); |
|
|
@ -214,7 +219,7 @@ namespace Networking.Server |
|
|
|
/// <summary>
|
|
|
|
/// Network connection ID
|
|
|
|
/// </summary>
|
|
|
|
public int ID { get { return (conn != null) ? conn.connectionId : -1; }} |
|
|
|
public int ID { get { return (conn != null) ? conn.Hash() : -1; }} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Connection to Client
|
|
|
|