//获取玩家信息 public void MsgGetAchieve(Player player, ProtocolBase protoBase) { ProtocolBytes protocolRet = new ProtocolBytes(); protocolRet.AddString("GetAchieve"); protocolRet.AddInt(player.data.win); protocolRet.AddInt(player.data.fail); player.Send(protocolRet); Console.WriteLine("MsgGetScore " + player.id + player.data.win); }
//登录 //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(); }
//返回协议 : 0-正常下线 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 ProtocolBytes GetRoomInfo() { ProtocolBytes protocol = new ProtocolBytes(); protocol.AddString("GetRoomInfo"); //房间信息 protocol.AddInt(list.Count); foreach (Player py in list.Values) { protocol.AddString(py.id); protocol.AddInt(py.tempData.team); protocol.AddInt(py.data.win); protocol.AddInt(py.data.fail); int isOwner = py.tempData.isOwner ? 1 : 0; protocol.AddInt(isOwner); } return(protocol); }
public ProtocolBytes GetRoomList() { ProtocolBytes protocol = new ProtocolBytes(); protocol.AddString("GetRoomList"); //数量 int count = list.Count; protocol.AddInt(count); for (int i = 0; i < count; i++) { Room room = list[i]; protocol.AddInt(room.list.Count); protocol.AddInt((int)room.status); } return(protocol); }
//创建 public void MsgCreateRoom(Player player, ProtocolBase protoBase) { ProtocolBytes protocol = new ProtocolBytes(); protocol.AddString("CreateRoom"); //条件检测 if (player.tempData.status != PlayerTempData.Status.None) { protocol.AddInt(-1); player.Send(protocol); Console.WriteLine("MsgCreateRoom Fail" + player.id); return; } RoomMgr.instance.CreateRoom(player); protocol.AddInt(0); player.Send(protocol); Console.WriteLine("MsgCreateRoom ok" + player.id); }
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); } }
//start public void MsgStartFight(Player player, ProtocolBase protoBase) { ProtocolBytes protocol = new ProtocolBytes(); protocol.AddString("StartFight"); if (player.tempData.status != PlayerTempData.Status.Room) { Console.WriteLine("MsgStartFight status err " + player.id); protocol.AddInt(-1); player.Send(protocol); return; } if (!player.tempData.isOwner) { Console.WriteLine("MsgStartFight owner err " + player.id); protocol.AddInt(-1); player.Send(protocol); return; } Room room = player.tempData.room; if (!room.CanStart()) { Console.WriteLine("MsgStartFight Canstart err " + player.id); protocol.AddInt(-1); player.Send(protocol); return; } protocol.AddInt(0); player.Send(protocol); room.StartFight(); }
//离开 public void MsgLeaveRoom(Player player, ProtocolBase protoBase) { ProtocolBytes protocol = new ProtocolBytes(); protocol.AddString("LeaveRoom"); //条件检测 if (player.tempData.status != PlayerTempData.Status.Room) { protocol.AddInt(-1); player.Send(protocol); Console.WriteLine("MsgLeaveRoom status err" + player.id); return; } protocol.AddInt(0); player.Send(protocol); Room room = player.tempData.room; RoomMgr.instance.LeaveRoom(player); if (room != null) { room.Broadcast(room.GetRoomInfo()); } }
//更新信息 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); }