Esempio n. 1
0
 public void ForceShutdown()
 {
     if (shutdown)
         return;
     shutdown = true;
     foreach (ServerPlayer temp in _players)
     if (temp!=null && !temp.isRemoved())
     {
         ServerMessage str = new ServerMessage(Protocol.netServerShutdown);
         str.WriteWord(33);
         temp.SendMessage(str, 0);
         OnClientRemove(temp);
     }
     Environment.Exit(0);
 }
Esempio n. 2
0
        private void HandleClientComm(object obj)
        {
            TcpClient tcpClient = (TcpClient)obj;
            NetworkStream clientStream = tcpClient.GetStream();
            ServerPlayer client = this.AllocateClient(tcpClient);

            if (client == null)
            {
                client = new ServerPlayer(tcpClient);
                ServerMessage dest = new ServerMessage(Protocol.netServerError);
                dest.WriteWord(Protocol.errServerFull);
                dest.WriteString(null);
                client.SendMessage(dest, 0);
                return;
            }

            playersOnline++;

            int bytesRead;
            byte[] buffer = new byte[1024];

            while (!client.isRemoved() && !this.shutdown)
            {
                ServerQueuedMessage temp = new ServerQueuedMessage();
                temp.client = client;
                bytesRead = 0;

                try
                {
                    if (client.outdatedVersion)
                    {
                        ServerMessage dest = new ServerMessage(Protocol.netServerError);
                        dest.WriteWord(Protocol.errInvalidVersion);
                        dest.WriteString(null);

                        client.SendMessage(dest, 0);
                    }

                    if (client.accountID>0)
                        Utils.Log("Waiting for client " + client.accountID + " packets..", 2);

                    ServerMessage msg = new ServerMessage(clientStream, buffer, ref bytesRead);
                }
                catch (Exception e)
                {
                    //a socket error has occured
                    Utils.Log("Socket error in client with id " + client.accountID, -1);
                    break;
                }

                if (bytesRead == 0)
                {
                    Utils.Log("Client with id " + client.accountID + " disconnected", 0);
                    //the client has disconnected from the server
                    break;
                }

                //protocol.HandleMessage(msg.header, msg.client, msg.data);
                messagequeue.Enqueue(temp);
            }

            OnClientRemove(client);
            client.removed = true;
            this.playersOnline--;

            tcpClient.Close();
            tcpClient = null;

            System.GC.Collect();
        }
Esempio n. 3
0
        public ServerMessage GetKeysMessage()
        {
            UInt16 count = 0;

            foreach (ServerPlayerKey temp in _keys)
            if (temp.kind == GameSaveKeyType.savekey_Map)
            {
            count++;
            }

            ServerMessage Result = null;
            if (count<=0)
            return null;

            Result = new ServerMessage(Protocol.netSyncLocal);
            Result.WriteWord(count);
            foreach (ServerPlayerKey temp in _keys)
            if (temp.kind == GameSaveKeyType.savekey_Map)
            {
            Result.WriteString(temp.key);
            Result.WriteString(temp.value);
            }

            return Result;
        }