I know it’s deprecated, but I’m still using it. I don’t understand why I keep getting unknown message error. It seems to me that I am registering the message id numbers in my protocol class. If you can point out my error, I would appreciate it. This is for a dedicated login server. I’ve seen a few other posts like this in the past, but I’m afraid I can’t identify my mistake. Here is the code:
Protocol:
public class Protocols : NetworkBehaviour
{
public class CharDataNetworkProtocol
{
public static readonly short RequestCreateAccount = 401;
public static readonly short ResponseCreateAccount = 403;
}
public class RequestCreateAccountMessage : MessageBase
{
public string Account_Name;
public string email;
public string password;
}
public class ResponseCreateAccountMessage : MessageBase
{
public bool success;
public string error;
}
}
Client Side:
public class ClientSide
{
NetworkClient handlerclient = new NetworkClient();
protected override void RegisterNetworkHandlers()
{
handlerclient.RegisterHandler(CharDataNetworkProtocol.ResponseCreateAccount, OnResponseCreateAccount);
}
protected override void UnregisterNetworkHandlers()
{
handlerclient.UnregisterHandler(CharDataNetworkProtocol.ResponseCreateAccount);
}
private void OnEnable()
{
RegisterNetworkHandlers();
}
private void OnDisable()
{
UnregisterNetworkHandlers();
}
public void Send_Create_Account(string email, string acct_name, string pswd)
{
var msg = new RequestCreateAccountMessage();
msg.Account_Name = acct_name;
msg.email = email;
msg.password = pswd;
clientApi.masterServerClient.client.Send(CharDataNetworkProtocol.RequestCreateAccount, msg);
}
}
Server Side:
public class ServerSide
{
protected override void RegisterNetworkHandlers()
{
NetworkServer.RegisterHandler(CharDataNetworkProtocol.RequestCreateAccount, OnRequestCreateAccount);
}
protected override void UnregisterNetworkHandlers()
{
NetworkServer.UnregisterHandler(CharDataNetworkProtocol.RequestCreateAccount);
}
public override void OnEnable()
{
RegisterNetworkHandlers();
}
public override void OnDisable()
{
UnregisterNetworkHandlers();
}
protected virtual void OnRequestCreateAccount(NetworkMessage netMsg)
{
var msg = netMsg.ReadMessage<RequestCreateAccountMessage>();
if (msg != null)
{
StartCoroutine(npgsql_db.Register_New_Account(msg.email, msg.Account_Name, msg.password, token =>
{
var responseMsg = new ResponseCreateAccountMessage();
responseMsg.success = true;
netMsg.conn.Send(CharDataNetworkProtocol.ResponseCreateAccount, responseMsg);
},
error =>
{
var responseMsg = new ResponseCreateAccountMessage();
responseMsg.success = false;
responseMsg.error = error;
netMsg.conn.Send(CharDataNetworkProtocol.ResponseCreateAccount, responseMsg);
}));
}
}
}