public Server() { ipAddress = null; tcpListener = null; serverThread = null; idCounter = 0; lobby = new Lobby(); }
public Server() { ipAddress = null; tcpListener = null; serverthread = null; clientsockets = null; gamelist = null; lobby = null; }
public GameServer(int port) { var configuration = new NetPeerConfiguration("HORSEGLUERTS"); configuration.Port = port; sendBuffer = new List<byte>(); server = new NetServer(configuration); ServerState = ServerStates.InLobby; gameMode = null; lobby = new Lobby(this); }
public static int Main(String[] args) { Server.ReceptionArea reception = new Server.ReceptionArea(); Server.MatchArea matchArea = new Server.MatchArea(); Server.Lobby lobby = new Server.Lobby(); reception.ClientEntered += lobby.Enter; lobby.MatchFound += matchArea.StartMatch; matchArea.GameOver += (result, a, b) => ProccesGameResult(result, a, b, lobby); reception.Start(); return(0); }
public void stratserver(String _ip, Int32 _port) { try { serverthread = new Thread(() => { ipAddress = IPAddress.Parse(_ip); tcpListener = new TcpListener(ipAddress, _port); tcpListener.Start(); ServerInfoEventArgs args = new ServerInfoEventArgs(); args.consoleinfo = "The server is running at port " + _port + " ...\n"; OnNeedLog(args); args.consoleinfo = "The local End point is: " + tcpListener.LocalEndpoint + "\n"; OnNeedLog(args); args.consoleinfo = "Waiting for a connection.....\n"; OnNeedLog(args); clientsockets = new List<Socket>(); gamelist = new List<Game>(); lobby = new Lobby(); while (true) { if (tcpListener.Pending()) { clientsockets.Add(tcpListener.AcceptSocket()); acceptConnection(100); } } }); serverthread.Start(); } catch (Exception e) { Console.WriteLine("Error..... " + e.Message); } }
private static void ProccesGameResult(Game.Result result, Server.Client a, Server.Client b, Server.Lobby lobby) { switch (result.type) { case Game.Result.Type.Ok: if (result.winner != null) { Console.WriteLine("winner: {0}", result.winner.name); } else { Console.WriteLine("tie {0} between {1}", a.name, b.name); } break; case Game.Result.Type.Error: Console.WriteLine("some error while playing"); if (a.client.Client.IsConnected() && !b.client.Client.IsConnected()) { Message.Util.Send(a.client.GetStream(), new Message.OpponentDisconnected()); } if (!a.client.Client.IsConnected() && b.client.Client.IsConnected()) { Message.Util.Send(b.client.GetStream(), new Message.OpponentDisconnected()); } break; } if (a.client.Client.IsConnected()) { lobby.Enter(a); } else { Console.WriteLine("{0} disconnected while playing", a); } if (b.client.Client.IsConnected()) { lobby.Enter(b); } else { Console.WriteLine("{0} disconnected while playing", b); } }
private void endLogin(string username) { DataSender.DataSender.Login(ref username); Lobby lobby = new Lobby(username, this); lobby.Show(); this.Hide(); }
public static void RemoveLobby(int id) { Lobby l = lobbyIds[id]; lobbies.Remove(l); }
//* зависит от логики public static void AddLobby(Lobby lobby) { lobbies.Add(lobby); lobbyIds.Add(lobby.Id, lobby); }
public RemoteInvokeMethod Create(LobbyInfo room) { var creatorId = room.PlayerId; var lobbyName = room.Name; var maxPlayer = room.MaxPlayers; var args = new List<SerializableType>(); if (!Lobbies.ContainsKey(lobbyName)) { var player = Players.SingleOrDefault(x => x.Id == creatorId); var newLobby = new Lobby(lobbyName, creatorId, maxPlayer, room.GameType); player.Team = Team.Red; player.Lobby = lobbyName; player.State = State.Join; player.Slot = 0; newLobby.Players.Add(player); Lobbies.Add(lobbyName, newLobby); var board = new BoardBehavior(BoardSizeWidth, BoardSizeHeight, lobbyName) { NetworkHandler = this }; Games.Add(lobbyName, board); var message = new ResponseMessage { Response = Response.Succed.ToString(), Message = room.Name }; SendUnits(player); args.Add(message); var lobby = new List<SerializableType> { room }; var response = new RemoteInvokeMethod(Command.SyncRooms, lobby); var bytes = RemoteInvokeMethod.WriteToStream(response); var clients = Players.Where(client => client.State == State.Lobby); foreach (var client in clients) { client.Sock.Send(bytes, bytes.Length, 0); } return new RemoteInvokeMethod(args); } args.Add(new ResponseMessage { Response = Response.Fail.ToString(), Message = "Room name already exist." }); return new RemoteInvokeMethod(args); }