예제 #1
0
        public void AddPlayer(ServerPlayer player)
        {
            if (player == null)
            return;

            foreach (ServerPlayer other in _players)
            if (other.accountID == player.accountID) {
                return;
            }

            foreach (ServerPlayer other in _players) {
            ServerMessage msg = new ServerMessage(Protocol.netPlayerAdd);
            msg.WriteInteger(this._ID);
            msg.WriteString(this._region.Name);
            msg.WriteInteger(other.TX);
            msg.WriteInteger(other.TY);
            msg.WriteByte(other.level);
            player.SendMessage(msg, other.accountID);
            msg = null;

            msg = other.GetKeysMessage();
            if (msg!=null) {
                player.SendMessage(msg, other.accountID);
                msg = null;
            }
            }

            _players.Add(player);
        }
예제 #2
0
 public void Write(ServerMessage str)
 {
     str.WriteBoolean(sleepClause);
     str.WriteBoolean(speciesClause);
     str.WriteBoolean(evasionClause);
     str.WriteBoolean(OHKOClause);
     str.WriteBoolean(equalizeLevels);
     str.WriteString(bannedMonsters);
 }
예제 #3
0
 public override void Write(ServerMessage str)
 {
     base.Write(str);
     str.WriteByte(switchIndex);
     str.WriteByte(resetStats);
     str.WriteString(switchMsg);
 }
예제 #4
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();
        }
예제 #5
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;
        }