//处理登录 public void MsgLogin(Conn conn, ProtocolBase protoBase) { //获取数值 int start = 0; ProtocolBytes protocol = (ProtocolBytes)protoBase; string protoName = protocol.GetString(start, ref start); string username = protocol.GetString(start, ref start); string password = protocol.GetString(start, ref start); string strFormat = "[收到登录协议 ]" + conn.GetAddress(); Console.WriteLine(strFormat + " 用户名: " + username + " 密码: " + password); //构建返回协议 ProtocolBytes protocolRet = new ProtocolBytes(); protocolRet.AddString("Login"); //验证 if (!ServerSQL.instance.CheckPassWord(username, password)) { protocolRet.AddInt(-1); conn.Send(protocolRet); return; } //是否已经登录 ProtocolBytes protocolLogout = new ProtocolBytes(); protocolLogout.AddString("Logout"); if (!Player.KickOff(username, protocolLogout)) { protocolRet.AddInt(-1); conn.Send(protocolRet); return; } //获取玩家数据 PlayerData playerData = ServerSQL.instance.GetPlayerData(username); if (playerData == null) { protocolRet.AddInt(-1); conn.Send(protocolRet); return; } conn.player = new Player(username, conn); conn.player.data = playerData; //事件触发 ServerTCP.instance.handlePlayerEvent.OnLogin(conn.player); //返回 protocolRet.AddInt(0); conn.Send(protocolRet); ServerTCP.instance.ShowOnlineSQL(conn.player); return; }
//登录 public void MsgLogin(Conn conn, ProtocolBase protocolBase) { int start = 0; ProtocolBytes protocol = (ProtocolBytes)protocolBase; string protoName = protocol.GetString(start, ref start); string id = protocol.GetString(start, ref start); string pw = protocol.GetString(start, ref start); string strFormat = "[收到登录协议] " + conn.GetAddr(); Console.WriteLine(strFormat + " 用户名: " + id + " 密码: " + pw); //构建返回协议 protocol = new ProtocolBytes(); protocol.AddString("Login"); //验证 if (!DataMgr.instance.CheckPassWord(id, pw)) { protocol.AddInt(-1); conn.Send(protocol); return; } //是否已经登录 ProtocolBytes protocolLogout = new ProtocolBytes(); protocolLogout.AddString("Logout"); if (!Player.KickOff(id, protocolLogout)) { protocol.AddInt(-2); conn.Send(protocol); return; } //获取玩家数据 PlayerData playerData = DataMgr.instance.GetPlayerData(id); conn.player = new Player(id, conn); conn.player.data = playerData; if (playerData == null) { protocol.AddInt(-3); conn.Send(protocol); } else { //事件触发 Serv.instance.handlePlayerEvent.OnLogin(conn.player); protocol.AddInt(0); conn.Send(protocol); } //返回 return; }
// Protocol: Login // Rec Args: string[id] string[pw] // Return: int[0-success] int[-1-fail] public void MsgLogin(Conn conn, ProtocolBase protoBase) { ProtocolBytes protocol = (ProtocolBytes)protoBase; int start = 0; string protoName = protocol.GetString(start, ref start); string id = protocol.GetString(start, ref start); string pw = protocol.GetString(start, ref start); Console.WriteLine("[HandleConnMsg.MsgLogin] Receive Login protocol: id[" + id + "] pw[" + pw + "]"); ProtocolBytes protocolRet = new ProtocolBytes(); protocolRet.AddString("Login"); if (!DataMgr.instance.CheckPassword(id, pw)) { protocolRet.AddInt32(-1); conn.Send(protocolRet); return; } ProtocolBytes protocolLogout = new ProtocolBytes(); protocolLogout.AddString("Logout"); if (!Player.KickOff(id, protocolLogout)) { protocolRet.AddInt32(-1); conn.Send(protocolRet); return; } PlayerData playerData = DataMgr.instance.GetPlayerData(id); if (playerData == null) { protocolRet.AddInt32(-1); conn.Send(protocolRet); return; } conn.player = new Player(id, conn); conn.player.data = playerData; ServNet.instance.handlePlayerEvent.OnLogin(conn.player); protocolRet.AddInt32(0); conn.Send(protocolRet); }
public void MsgRegister(Conn conn, ProtocolBase protocolBase) { //获取数值 ProtocolBytes protocolBytes = (ProtocolBytes)protocolBase; int start = 0; string name = protocolBytes.GetString(start, ref start); string id = protocolBytes.GetString(start, ref start); string pw = protocolBytes.GetString(start, ref start); Console.WriteLine("[注册协议]" + "用户名:" + id + "密码:" + pw); protocolBytes = new ProtocolBytes(); protocolBytes.AddString("Register"); //注册 if (DataMgr.instance.Register(id, pw)) { protocolBytes.AddInt(0); //创建角色 DataMgr.instance.CreatePlayer(id); } else { protocolBytes.AddInt(-1); } conn.Send(protocolBytes); }
//处理注册 public void MsgRegister(Conn conn, ProtocolBase protoBase) { //获取数值 int start = 0; ProtocolBytes protocol = (ProtocolBytes)protoBase; string protoName = protocol.GetString(start, ref start); string username = protocol.GetString(start, ref start); string password = protocol.GetString(start, ref start); string strFormat = "[收到注册协议 ]" + conn.GetAddress(); Console.WriteLine(strFormat + " 用户名: " + username + " 密码: " + password); //构建返回协议 protocol = new ProtocolBytes(); protocol.AddString("Register"); //注册 if (ServerSQL.instance.Register(username, password)) { protocol.AddInt(0); } else { protocol.AddInt(-1); } //创建角色 ServerSQL.instance.CreatePlayer(username); //返回协议给客户端 conn.Send(protocol); }
//注册 public void MsgRegister(Conn conn, ProtocolBase protoBase) { int start = 0; ProtocolBytes protocol = (ProtocolBytes)protoBase; string protoName = protocol.GetString(start, ref start); string id = protocol.GetString(start, ref start); string pw = protocol.GetString(start, ref start); string strFormat = "[收到注册协议] " + conn.GetAddr(); Console.WriteLine(strFormat + " 用户名: " + id + " 密码: " + pw); //构建返回协议 protocol = new ProtocolBytes(); protocol.AddString("Register"); //注册 if (DataMgr.instance.Register(id, pw)) { protocol.AddInt(0); } else { protocol.AddInt(-1); } //返回协议给客户端 conn.Send(protocol); }
// Protocol: Register // Rec Args: string[id] string[pw] // Return: int[0-success] int[-1-fail] public void MsgRegister(Conn conn, ProtocolBase protoBase) { ProtocolBytes protocol = (ProtocolBytes)protoBase; int start = 0; string protoName = protocol.GetString(start, ref start); string id = protocol.GetString(start, ref start); string pw = protocol.GetString(start, ref start); Console.WriteLine("[HandleConnMsg.MsgRegister] Receive Register protocol: id[" + id + "] pw[" + pw + "]"); ProtocolBytes protocolRet = new ProtocolBytes(); protocolRet.AddString("Register"); if (!DataMgr.instance.Register(id, pw)) { protocolRet.AddInt32(-1); } else { protocolRet.AddInt32(0); } DataMgr.instance.CreatePlayer(id); conn.Send(protocolRet); }
public void MsgLogin(Conn conn, ProtocolBase protocolBase) { int start = 0; ProtocolBytes protocolBytes = (ProtocolBytes)protocolBase; string name = protocolBytes.GetString(start, ref start); string id = protocolBytes.GetString(start, ref start); string pw = protocolBytes.GetString(start, ref start); Console.WriteLine("[登入协议]" + "用户名:" + id + "密码:" + pw); protocolBytes = new ProtocolBytes(); protocolBytes.AddString("Login"); //验证 if (!DataMgr.instance.CheckPassWord(id, pw)) { protocolBytes.AddInt(-1); conn.Send(protocolBytes); return; } //是否已经登入,如果已登入,强制退出,并且此次登入失效 ProtocolBytes protocolLogout = new ProtocolBytes(); protocolLogout.AddString("Logout"); if (!Player.KickOff(id, protocolLogout)) { protocolBytes.AddInt(-1); conn.Send(protocolBytes); return; } //获取玩家数据 PlayerData playerData = DataMgr.instance.GetPlayerData(id); if (playerData == null) { protocolBytes.AddInt(-1); conn.Send(protocolBytes); return; } conn.player = new Player(id, conn); conn.player.data = playerData; //事件触发 ServNet.getInstance().HandlePlayerEvent.OnLogin(conn.player); protocolBytes.AddInt(0); conn.Send(protocolBytes); return; }
//处理验证客户端是否已通过外网映射IP连接到服务器 public void MsgIsServer(Conn conn, ProtocolBase protoBase) { ProtocolBytes protocol = new ProtocolBytes(); Console.WriteLine("[收到服务器验证协议 ]" + conn.GetAddress() + "\n"); protocol.AddString("IsServer"); conn.Send(protocol); }
//下线 public void MsgLogout(Conn conn, ProtocolBase protoBase) { ProtocolBytes protocol = new ProtocolBytes(); protocol.AddString("Logout"); protocol.AddInt(0); if (conn.player == null) { conn.Send(protocol); conn.Close(); } else { conn.Send(protocol); conn.player.Logout(); } }
//处理登出 public void MsgLogout(Conn conn, ProtocolBase protoBase) { ProtocolBytes protocol = new ProtocolBytes(); Console.WriteLine("[收到登出协议 ]" + conn.GetAddress() + "\n"); protocol.AddString("Logout"); protocol.AddInt(0); if (conn.player == null) { conn.Send(protocol); conn.Close(); } else { conn.Send(protocol); conn.player.Logout(); } }
// Protocol: Logout // Rec Args: int[logout reason] // Return: int[0-logout normally] public void MsgLogout(Conn conn, ProtocolBytes protoBase) { ProtocolBytes protocolRet = new ProtocolBytes(); protocolRet.AddString("Logout"); protocolRet.AddInt32(0); Console.WriteLine("[HandleConnMsg.MsgLogout] Receive Logout protocol."); conn.Send(protocolRet); if (conn.player != null) { conn.player.Logout(); } else { conn.Close(); } }