public bool addPlayer(ClientSide player) { if (team1.isFull() && team2.isFull()) { return(false); } if (team1.size() <= team2.size()) { team1.addPlayer(player); Console.WriteLine("[+] " + player.Name + " join team 1"); } else { team2.addPlayer(player); Console.WriteLine("[+] " + player.Name + " join team 2"); } if (team1.isFull() && team2.isFull()) { lock (this) { Monitor.Pulse(this); } } return(true); }
private ClientSide getClientSideByConnection(Connection connection) { ClientSide ret = null; foreach (var user in waiting_room) { if (user.Socket == connection) { ret = user; } } return(ret); }
public void FirstConnect(Connection connection) { var tmp = new ClientSide(connection); waiting_room.Add(tmp); var req = new ServerRequest(); req.Opcode = OpCodeEnum.WELCOME; Thread.Sleep(1000); connection.SendObject("ServerRequest", req); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("[*] User added to waiting room"); Console.WriteLine("[*] Witing room size : " + waiting_room.Count); Console.ForegroundColor = ConsoleColor.White; }
public void setName(ClientRequest resp, Connection connection) { ClientSide user = getClientSideByConnection(connection); if (user != null) { user.Name = resp.Name; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("[*] Name of new client : " + user.Name); Console.ForegroundColor = ConsoleColor.White; if (this._board.addPlayer(user)) { waiting_room.Remove(user); } } }
public bool addPlayer(ClientSide player) { if (P1 == null) { P1 = player; } else if (P2 == null) { P2 = player; } else { return(false); } return(true); }