static void Main(string[] args) { EventManager ev = new EventManager(); ev.Register("Network.Game.GameStart", o => Console.WriteLine("le jeu débute")); Parser p = new Parser(); Client c = new Client("163.5.218.4", 4242, ev, p.Parse); new JoinLobby().Pack(c.Writer, Console.ReadLine(), "Zeus"); Console.ReadLine(); }
public GameHost(ushort port, string map, byte maxplayers) { _parser = new Parser(); _em = new EventManager(); _map = map; _maxPlayers = maxplayers; _port = port; OpenLobby(); }
static void InitServer(EventManager ev, ushort port) { var p = new Parser(); p.PacketNotFound += (pck) => Console.WriteLine("Packet inconnu [ID={0}]", pck.Header.ID); _s = new Server(ev, p.Parse); _s.ClientConnected += (c) => Console.WriteLine("Client connected [{0}]", c.ToString()); _s.ClientDisconnected += (c) => Console.WriteLine("Client disconnected [{0}]", c.ToString()); _s.Start(port); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Server UP !"); Console.ForegroundColor = ConsoleColor.Gray; }
public Client(TcpClient client, IEventDispatcher eventDispatcher, Parser.ParserMethod parseMethod, ClientConnectedHandler onConnect = null) { _client = client; Connected = true; _client.NoDelay = true; _eventDispatcher = eventDispatcher; _parseMethod = parseMethod; _networkInfos = _client.Client.RemoteEndPoint.ToString(); if (onConnect != null) onConnect.BeginInvoke(this, null, null); new Task(Receive).Start(); }
public void MasterOperation(bool register) { var m = new EventManager(); var p = new Parser(); var c = new Client(MasterServerHost, MasterServerPort, m, p.Parse); if (register) { new MasterAddServer().Pack(c.Writer, Server.Port, CurrentLobby.MapName, CurrentLobby.MaxPlayers, CurrentLobby.PlayersConnected); Console.WriteLine("Serveur enregistré sur Master"); } else { new MasterRemoveServer().Pack(c.Writer, Server.Port); Console.WriteLine("Serveur désenregistré sur Master"); } c.Disconnect(); }
public Client(string ip, int port, IEventDispatcher eventDispatcher, Parser.ParserMethod parseMethod, ClientConnectedHandler onConnect = null) { try { _client = new TcpClient(ip, port); Connected = true; _client.NoDelay = true; _eventDispatcher = eventDispatcher; _parseMethod = parseMethod; _networkInfos = _client.Client.RemoteEndPoint.ToString(); if (onConnect != null) onConnect.BeginInvoke(this, null, null); new Task(Receive).Start(); } catch (SocketException se) { Connected = false; } }
public Server(IEventDispatcher eventDispatcher, Parser.ParserMethod parseMethod) { _eventDispatcher = eventDispatcher; _parserMethod = parseMethod; }