//加入 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); }