//登录 //Login str 用户名 str 密码 //-1失败,0成功 public void MsgLogin(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.GetAdress(); Console.WriteLine(strFormat + " 用户名:" + id + " 密码:" + pw); //返回协议 ProtocolBytes protocolRet = new ProtocolBytes(); protocolRet.AddString("Login"); //验证 if (!DataMgr.instance.CheckPassWord(id, pw)) { protocolRet.AddInt(-1); conn.Send(protocolRet); return; } //是否已经登录 ProtocolBytes protocolLogout = new ProtocolBytes(); protocolLogout.AddString("Logout"); if (!Player.KickOff(id, protocolLogout)) { protocolRet.AddInt(-1); conn.Send(protocolRet); return; } PlayerData playerData = DataMgr.instance.GettPlayerData(id); if (playerData == null) { protocolRet.AddInt(-1); conn.Send(protocolRet); return; } conn.player = new Player(id, conn); conn.player.data = playerData; //事件触发 ServNet.instance.handlePlayerEvent.OnLogin(conn.player); //返回 protocolRet.AddInt(0); conn.Send(protocolRet); return; }
public void MsgHit(Player player, ProtocolBase protoBase) { int start = 0; ProtocolBytes protocol = (ProtocolBytes)protoBase; string protoName = protocol.GetString(start, ref start); string enemyName = protocol.GetString(start, ref start); float damage = protocol.GetFloat(start, ref start); long lastShootTime = player.tempData.lastShootTime; if (Sys.Getimetamp() - lastShootTime < 1) { Console.WriteLine("有点问题"); return; } player.tempData.lastShootTime = Sys.Getimetamp(); //Get Room if (player.tempData.status != PlayerTempData.Status.Fight) { return; } Room room = player.tempData.room; //life if (!room.list.ContainsKey(enemyName)) { Console.WriteLine("MsgHit net Contains enemy " + enemyName); return; } Player enemy = room.list[enemyName]; if (enemy == null) { return; } if (enemy.tempData.hp <= 0) { return; } enemy.tempData.hp -= damage; Console.WriteLine("MsgHit enemyname" + enemyName); ProtocolBytes protocolRet = new ProtocolBytes(); protocolRet.AddString("Hit"); protocolRet.AddString(player.id); protocolRet.AddString(enemy.id); protocolRet.AddFloat(damage); room.Broadcast(protocolRet); room.UpdateWin(); }
public void MsgShooting(Player player, ProtocolBase protoBase) { //获取数值 ProtocolBytes protocol = (ProtocolBytes)protoBase; int start = 0; string protoName = protocol.GetString(start, ref start); float posx = protocol.GetFloat(start, ref start); float posy = protocol.GetFloat(start, ref start); float posz = protocol.GetFloat(start, ref start); float rotx = protocol.GetFloat(start, ref start); float roty = protocol.GetFloat(start, ref start); float rotz = protocol.GetFloat(start, ref start); if (player.tempData.status != PlayerTempData.Status.Fight) { return; } Room room = player.tempData.room; ProtocolBytes protocolRet = new ProtocolBytes(); protocolRet.AddString("Shooting"); protocolRet.AddString(player.id); protocolRet.AddFloat(posx); protocolRet.AddFloat(posy); protocolRet.AddFloat(posz); protocolRet.AddFloat(rotx); protocolRet.AddFloat(roty); protocolRet.AddFloat(rotz); room.Broadcast(protocolRet); }
//加分 //无返回 public void MsgAddScore(Player player, ProtocolBase protoBase) { int start = 0; ProtocolBytes protocol = (ProtocolBytes)protoBase; string protoName = protocol.GetString(start, ref start); player.data.score += 1; Console.WriteLine("MsgAddScore " + player.id + " " + player.data.score.ToString()); }
public void MsgUpdateUnitInfo(Player player, ProtocolBase protocolBase) { int start = 0; ProtocolBytes protocol = (ProtocolBytes)protocolBase; string protoName = protocol.GetString(start, ref start); float posx = protocol.GetFloat(start, ref start); float posy = protocol.GetFloat(start, ref start); float posz = protocol.GetFloat(start, ref start); float rotx = protocol.GetFloat(start, ref start); float roty = protocol.GetFloat(start, ref start); float rotz = protocol.GetFloat(start, ref start); float gunRot = protocol.GetFloat(start, ref start); float gunRoll = protocol.GetFloat(start, ref start); //获取房间 if (player.tempData.status != PlayerTempData.Status.Fight) { return; } Room room = player.tempData.room; player.tempData.posX = posx; player.tempData.posY = posy; player.tempData.posZ = posz; player.tempData.lastUpdateTime = Sys.Getimetamp(); ProtocolBytes protocolRet = new ProtocolBytes(); protocolRet.AddString("UpdateUnitInfo"); protocolRet.AddString(player.id); protocolRet.AddFloat(posx); protocolRet.AddFloat(posy); protocolRet.AddFloat(posz); protocolRet.AddFloat(rotx); protocolRet.AddFloat(roty); protocolRet.AddFloat(rotz); protocolRet.AddFloat(gunRot); protocolRet.AddFloat(gunRoll); room.Broadcast(protocolRet); }
//加入 public void MsgEnterRoom(Player player, ProtocolBase proto) { int start = 0; ProtocolBytes protocol = (ProtocolBytes)proto; string protoName = protocol.GetString(start, ref start); int index = protocol.GetInt(start, ref start); Console.WriteLine("[收到 MsetenterRoom] " + player.id + "" + index); protocol = new ProtocolBytes(); protocol.AddString("EnterRoom"); if (index < 0 || index >= RoomMgr.instance.list.Count) { Console.WriteLine("MsgEnterRoom Index error" + player.id); protocol.AddInt(-1); player.Send(protocol); return; } Room room = RoomMgr.instance.list[index]; //判断房间状态 if (room.status != Room.Status.Prepare) { Console.WriteLine("MsgEnterRoom statuserr" + player.id); protocol.AddInt(-1); player.Send(protocol); return; } if (room.AddPlayer(player)) { room.Broadcast(room.GetRoomInfo()); protocol.AddInt(0); player.Send(protocol); } else { Console.WriteLine("MsgEnterRoom maxPlayer erro " + player.id); protocol.AddInt(-1); player.Send(protocol); } }
//更新信息 public void MsgUpdateInfo(Player player, ProtocolBase protoBase) { //获取分数 int start = 0; ProtocolBytes protocol = (ProtocolBytes)protoBase; string protoname = protocol.GetString(start, ref start); float x = protocol.GetFloat(start, ref start); float y = protocol.GetFloat(start, ref start); float z = protocol.GetFloat(start, ref start); int score = protocol.GetInt(start, ref start); Scene.Scener.instance.UpdateInfo(protoname, x, y, z, score); //广播 ProtocolBytes protocolret = new ProtocolBytes(); protocolret.AddString("UpdateInfo"); protocolret.AddString(player.id); protocolret.AddFloat(x); protocolret.AddFloat(y); protocolret.AddFloat(z); protocolret.AddInt(score); ServNet.instance.Broadcast(protocolret); }