Esempio n. 1
0
        public Server(string ip, int port, Main m)
        {
            this.m = m;
            long IP = NetPacket.stringToLongIP(ip);

            t      = new Thread(new ThreadStart(() => ServerSocketHandler.StartListening(IP, port)));
            t.Name = "ServerListenThread";
            t.Start();
        }
Esempio n. 2
0
        private void handleSendPacket()
        {
            NetPacket p;
            bool      rec = ToSendPacket.TryDequeue(out p);

            if (rec)
            {
                ServerSocketHandler.Send(p.addr, p.p);
            }
        }
Esempio n. 3
0
        private void handlePlayerPacket(PlayerPacket p)
        {
            ServerPlayerObject player;

            players.TryGetValue(p.username, out player);
            if (player != null)
            {
                if (p.status == PlayerStatus.Connecting)
                {
                    if (player.password == p.password)
                    {
                        player.online = true;
                    }
                }
                else if (p.status == PlayerStatus.Disconnecting)
                {
                    player.online = false;
                    IPEndPoint addr = new IPEndPoint(p.ip, p.port);
                    ServerSocketHandler.removeClient(addr);
                }
                else
                {
                    player.online = p.online;
                }
            }
            else
            {
                player = new ServerPlayerObject(p.ip, p.port, p.username, p.password, p.online, p.alive);
                Vector2 v = m.map.AddRandomUnit(p.username);
                updateTile(v);
                sendMap(new IPEndPoint(p.ip, p.port));
            }
            players.AddOrUpdate(p.username, player, (string k, ServerPlayerObject v) => player);
            p.password = "";
            p.ip       = 0;
            p.port     = 0;
            sendToAllClient(p);
        }