NetworkClient: m_MessageHandlers made public and renamed to handlers. No need to have a separate property, it can't be nulled anyway.

This commit is contained in:
vis2k 2019-01-16 21:48:44 +01:00
parent 76bd13c789
commit 28539c9d2f

View File

@ -19,7 +19,7 @@ public class NetworkClient
ushort m_ServerPort;
int m_ClientId = -1;
readonly Dictionary<short, NetworkMessageDelegate> m_MessageHandlers = new Dictionary<short, NetworkMessageDelegate>();
public readonly Dictionary<short, NetworkMessageDelegate> handlers = new Dictionary<short, NetworkMessageDelegate>();
protected NetworkConnection m_Connection;
protected enum ConnectState
@ -33,7 +33,7 @@ protected enum ConnectState
internal void SetHandlers(NetworkConnection conn)
{
conn.SetHandlers(m_MessageHandlers);
conn.SetHandlers(handlers);
}
public string serverIp { get { return m_ServerIp; } }
@ -41,8 +41,6 @@ internal void SetHandlers(NetworkConnection conn)
public ushort hostPort;
public NetworkConnection connection { get { return m_Connection; } }
public Dictionary<short, NetworkMessageDelegate> handlers { get { return m_MessageHandlers; } }
public bool isConnected { get { return connectState == ConnectState.Connected; } }
public NetworkClient()
@ -59,7 +57,7 @@ public NetworkClient(NetworkConnection conn)
SetActive(true);
m_Connection = conn;
connectState = ConnectState.Connected;
conn.SetHandlers(m_MessageHandlers);
conn.SetHandlers(handlers);
RegisterSystemHandlers(false);
}
@ -78,7 +76,7 @@ public void Connect(string serverIp, ushort serverPort)
// setup all the handlers
m_Connection = new NetworkConnection(m_ServerIp, m_ClientId, 0);
m_Connection.SetHandlers(m_MessageHandlers);
m_Connection.SetHandlers(handlers);
}
void PrepareForConnect()
@ -241,7 +239,7 @@ void GenerateDisconnectError(byte error)
void GenerateError(byte error)
{
NetworkMessageDelegate msgDelegate;
if (m_MessageHandlers.TryGetValue((short)MsgType.Error, out msgDelegate))
if (handlers.TryGetValue((short)MsgType.Error, out msgDelegate))
{
ErrorMessage msg = new ErrorMessage();
msg.value = error;
@ -271,11 +269,11 @@ internal void RegisterSystemHandlers(bool localClient)
public void RegisterHandler(short msgType, NetworkMessageDelegate handler)
{
if (m_MessageHandlers.ContainsKey(msgType))
if (handlers.ContainsKey(msgType))
{
if (LogFilter.Debug) { Debug.Log("NetworkClient.RegisterHandler replacing " + msgType); }
}
m_MessageHandlers[msgType] = handler;
handlers[msgType] = handler;
}
public void RegisterHandler(MsgType msgType, NetworkMessageDelegate handler)
@ -285,7 +283,7 @@ public void RegisterHandler(MsgType msgType, NetworkMessageDelegate handler)
public void UnregisterHandler(short msgType)
{
m_MessageHandlers.Remove(msgType);
handlers.Remove(msgType);
}
public void UnregisterHandler(MsgType msgType)