Exemple #1
0
 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();
 }
Exemple #2
0
 public GameHost(ushort port, string map, byte maxplayers)
 {
     _parser = new Parser();
     _em = new EventManager();
     _map = map;
     _maxPlayers = maxplayers;
     _port = port;
     OpenLobby();
 }
Exemple #3
0
        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;
        }
Exemple #4
0
        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();
        }
Exemple #5
0
        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();
        }
Exemple #6
0
        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;
            }
        }
Exemple #7
0
 public Server(IEventDispatcher eventDispatcher, Parser.ParserMethod parseMethod)
 {
     _eventDispatcher = eventDispatcher;
     _parserMethod = parseMethod;
 }