Action <int> _onRegister; // 错误码 public void Register(string accountName, string password, string nickName, Action <int> action) { Debug.Log("[C_Login_Register_0x0106]"); _onRegister = action; var data = new C_Login_Register_0x0106 { _accountName = accountName, _nickName = nickName, _password = password }; Singleton._serverCallback.AddCallback <S_Login_Register_0x0106>(OnRegister); Singleton._messageManager.Send(data); }
void OnRegister(Client peer, C_Login_Register_0x0106 msg) { Singleton._log.Info("C_Login_Register_0x0106" + ", client=" + peer._accountName); int rs = 0; if (peer == null) { rs = 1; } if (string.IsNullOrEmpty(msg._accountName)) { rs = 2; } Singleton._log.InfoFormat("[{0}] 帐号 {1} 注册!", msg.GetMessageID().ToHex() , (msg == null ? "null" : msg._accountName)); var newRs = Singleton._sqlServer.CheckAccount(msg._accountName, msg._password); if (newRs != Sql.EAccountResult.AccountNotExist) { // 帐号已存在 rs = 3; } var playerData = new PlayerData(); playerData._accountName = msg._accountName; playerData._nickName = msg._nickName; Singleton._sqlServer.Register(playerData, msg._password); Singleton._log.Info("connectId = " + peer.ConnectionId + ", 添加 " + msg._accountName); Singleton._clients[msg._accountName] = peer; peer._accountName = msg._accountName; Singleton._log.Info("S_Login_Register_0x0106" + ", client=" + peer._accountName); Send(peer, new S_Login_Register_0x0106 { _returnCode = rs, }); }