public void MsgGetScore(Player player, ProtocolBase protoBase) { ProtocolBytes protocolRet = new ProtocolBytes(); protocolRet.AddString("GetScore"); protocolRet.AddInt(player.data.ScoreHuman); protocolRet.AddInt(player.data.ScoreKiller); player.Send(protocolRet); Console.WriteLine("MsgGetScore " + player.id + " [" + player.data.ScoreHuman + " " + player.data.ScoreKiller + "] "); }
public void GameOver(object state) { delRoomTimer.Dispose(); delRoomTimer = null; lock (this) { this.state = State.Delete; lock (RoomMgr.instance.list) { RoomMgr.instance.list.Remove(this); } ProtocolBytes protocol = new ProtocolBytes(); protocol.AddString("GameOver"); protocol.AddInt((int)state); lock (list) { foreach (Player p in list.Values) { p.tempData.room = null; p.tempData.state = PlayerTempData.State.None; p.Send(protocol); if (p.tempData.isKiller) { if ((int)state == 1) { p.data.ScoreKiller++; } else { p.data.ScoreKiller--; } //DataMgr.instance.SavePlayer(p); } else { if ((int)state == 1) { p.data.ScoreHuman--; } else { p.data.ScoreHuman++; } //DataMgr.instance.SavePlayer(p); } } } } }
public void CheckFight() { if (onloadPlayers == RoomMgr.maxPlayers) { state = State.Fight; ProtocolBytes protocol = new ProtocolBytes(); protocol.AddString("StartFight"); Broadcast(protocol); delRoomTimer = new Timer(GameOver, 2, RoomMgr.gameTime, Timeout.Infinite); } }
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"); int ckstate = DataMgr.instance.CheckPassWord(id, pw); if (ckstate != 200) { protocolRet.AddInt(ckstate); conn.Send(protocolRet); return; } ProtocolBytes protocolLogout = new ProtocolBytes(); protocolLogout.AddString("Logout"); int kfstate = Player.KickOff(id, protocolLogout); if (kfstate != 200) { protocolRet.AddInt(kfstate); conn.Send(protocolRet); return; } PlayerData playerData = DataMgr.instance.GetPlayerData(id); if (playerData == null) { protocolRet.AddInt(502); conn.Send(protocolRet); return; } conn.player = new Player(id, conn); conn.player.data = playerData; ServNet.instance.handlePlayerEvent.OnLogin(conn.player); protocolRet.AddInt(200); conn.Send(protocolRet); }
public void SendPlayerList(Player player) { ProtocolBytes protocol = new ProtocolBytes(); protocol.AddString("GetList"); foreach (Player p in list.Values) { protocol.AddString(p.id); protocol.AddFloat(p.sceneData.x); protocol.AddFloat(p.sceneData.y); //protocol.AddInt(p.sceneData.score); } player.Send(protocol); }
public void DelPlayer(string id) { lock (list) { if (!list.Remove(id)) { return; } } ProtocolBytes protocol = new ProtocolBytes(); protocol.AddString("PlayerLeave"); protocol.AddString("id"); ServNet.instance.Broadcast(protocol); }
public void MsgLogout(Conn conn, ProtocolBase protoBase) { ProtocolBytes protocol = new ProtocolBytes(); protocol.AddString("Logout"); protocol.AddInt(200); conn.Send(protocol); if (conn.player == null) { conn.Close(); } else { conn.player.Logout(); } }
public void StartLoad() { state = State.Load; onloadPlayers = 0; foreach (Player player in list.Values) { player.tempData.isOnload = false; player.sceneData = new SceneData(); } ProtocolBytes protocol = new ProtocolBytes(); protocol.AddString("StartLoad"); protocol.AddInt(RoomMgr.random.Next(RoomMgr.maxMaps)); Broadcast(protocol); }
public void SendPlayerList(Player player) { int count = list.Count; ProtocolBytes protocol = new ProtocolBytes(); protocol.AddString("GetList"); protocol.AddInt(count); foreach (ScenePlayer p in list.Values) { protocol.AddString(p.id); protocol.AddFloat(p.x); protocol.AddFloat(p.y); protocol.AddInt(p.score); } player.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.GetAdress(); Console.WriteLine(strFormat + " 用户名: " + id + " 密码: " + pw); protocol = new ProtocolBytes(); protocol.AddString("Register"); protocol.AddInt(DataMgr.instance.Register(id, pw)); DataMgr.instance.CreatePlayer(id); conn.Send(protocol); }
public void DeleteRoom(object state) { delRoomTimer.Dispose(); delRoomTimer = null; lock (this) { if (this.state != State.Prepare || readyPlayers == RoomMgr.maxPlayers) { return; } this.state = State.Delete; readyPlayers = 0; lock (RoomMgr.instance.list) { RoomMgr.instance.list.Remove(this); } ProtocolBytes protocol = new ProtocolBytes(); protocol.AddString("LeaveRoom"); if (state == null) { protocol.AddInt(408); // 房间超时 } else { protocol.AddInt(410); // 玩家退出 Player player = (Player)state; protocol.AddString(player.id); } lock (list) { foreach (Player player in list.Values) { player.tempData.room = null; player.tempData.state = PlayerTempData.State.None; player.Send(protocol); } } } }
public void MsgKilledHuman(Player player, ProtocolBase protoBase) { if (!player.tempData.isKiller) { return; } Room room = player.tempData.room; if (room == null) { return; } int start = 0; ProtocolBytes protocol = (ProtocolBytes)protoBase; string protoName = protocol.GetString(start, ref start); string humanID = protocol.GetString(start, ref start); room.KilledHuman(room.list[humanID]); }
public void KilledHuman(Player player) { if (player.tempData.isKiller) { return; } if (!player.sceneData.isLived) { return; } player.sceneData.isLived = false; ProtocolBytes protocolRet = new ProtocolBytes(); protocolRet.AddString("KilledHuman"); protocolRet.AddString(player.id); Broadcast(protocolRet); CheckOver(); }
public void MsgLeaveRoom(Player player, ProtocolBase protoBase) { //if (player.tempData.room == null) return; //Room room = player.tempData.room; //room.DelPlayer(player.id); //if (room.list.Count == 0) //{ // lock (RoomMgr.instance.list) // { // RoomMgr.instance.list.Remove(room); // } //} ProtocolBytes protocol = new ProtocolBytes(); protocol.AddString("LeaveRoom"); if (player.tempData.state != PlayerTempData.State.Room) { Console.WriteLine("[MsgLeaveRoom] 玩家状态错误"); protocol.AddInt(417); player.Send(protocol); return; } if (player.tempData.room == null || player.tempData.room.delRoomTimer == null) { Console.WriteLine("[MsgLeaveRoom] 房间已删除,无需离开"); protocol.AddInt(418); player.Send(protocol); return; } lock (player.tempData.room) { player.tempData.room.DeleteRoom(player); } //protocol.AddInt(200); //player.Send(protocol); }
public void MsgLeaveQueue(Player player, ProtocolBase protoBase) { ProtocolBytes protocol = new ProtocolBytes(); protocol.AddString("LeaveQueue"); bool flag; lock (RoomMgr.instance.queueLock) { if (player.tempData.state != PlayerTempData.State.Queue) { Console.WriteLine("[MsgLeaveQueue] 已不在队列,无法退出"); protocol.AddInt(417); player.Send(protocol); return; } player.tempData.state = PlayerTempData.State.None; if (player.tempData.isKiller) { flag = RoomMgr.instance.killers.Remove(player); } else { flag = RoomMgr.instance.humans.Remove(player); } } if (!flag) { Console.WriteLine("[MsgLeaveQueue] Remove失败,无法退出"); protocol.AddInt(500); player.Send(protocol); return; } protocol.AddInt(200); player.Send(protocol); }
public void CreateRoom(List <Player> players) { Room room = new Room(); lock (list) { list.Add(room); } foreach (Player p in players) { p.tempData.isReady = false; room.AddPlayer(p); } ProtocolBytes protocol = new ProtocolBytes(); protocol.AddString("EnterRoom"); foreach (string id in room.list.Keys) { protocol.AddString(id); } room.Broadcast(protocol); }
public void MsgEnterKiller(Player player, ProtocolBase protoBase) { ProtocolBytes protocol = new ProtocolBytes(); protocol.AddString("EnterKiller"); lock (RoomMgr.instance.queueLock) { if (player.tempData.state != PlayerTempData.State.None) { Console.WriteLine("[MsgEnterKiller] 状态不为None,无法加入"); protocol.AddInt(417); player.Send(protocol); return; } player.tempData.state = PlayerTempData.State.Queue; player.tempData.isKiller = true; RoomMgr.instance.killers.Add(player); } protocol.AddInt(200); player.Send(protocol); RoomMgr.instance.TestMatch(); }