コード例 #1
0
ファイル: ServerMap.cs プロジェクト: Relfos/MinimonServer
        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
ファイル: ServerMap.cs プロジェクト: Relfos/MinimonServer
 public void Broadcast(ServerMessage Msg, UInt32 owner)
 {
     foreach (ServerPlayer player in _players)
     if (player!= null && player.accountID != owner) {
         player.SendMessage(Msg, owner);
     }
 }
コード例 #3
0
ファイル: ServerParty.cs プロジェクト: Relfos/MinimonServer
        public bool AddPlayer(ServerPlayer player)
        {
            if (this.HasPlayer(player)) {
                return true;
            }

            if (this.IsFull()) {
                return false;
            }

            for (int i = 0; i < Settings.MaxPartySize; i++)
            if (_members[i] == null)
            {
                _members[i] = player;
                ServerMessage msg = new ServerMessage(Protocol.netSquadJoin);
                byte n = (byte)i;
                msg.WriteByte(n);
                this.Broadcast(msg, player.accountID);
                player.SendMessage(msg, player.accountID);
                msg = null;

                for (int j = 0; j < Settings.MaxPartySize; j++)
                if (_members[j]!= null && j!=i)
                {
                    msg = new ServerMessage(Protocol.netSquadJoin);
                    msg.WriteByte(n);

                    player.SendMessage(msg, _members[i].accountID);
                }

                break;
            }

            return true;
        }
コード例 #4
0
ファイル: ServerBattle.cs プロジェクト: Relfos/MinimonServer
 public void Read(ServerMessage str)
 {
     sleepClause = str.ReadBoolean();
     speciesClause = str.ReadBoolean();
     evasionClause = str.ReadBoolean();
     OHKOClause = str.ReadBoolean();
     equalizeLevels = str.ReadBoolean();
     bannedMonsters = str.ReadString();
 }
コード例 #5
0
ファイル: ServerBattle.cs プロジェクト: Relfos/MinimonServer
 public void Write(ServerMessage str)
 {
     str.WriteBoolean(sleepClause);
     str.WriteBoolean(speciesClause);
     str.WriteBoolean(evasionClause);
     str.WriteBoolean(OHKOClause);
     str.WriteBoolean(equalizeLevels);
     str.WriteString(bannedMonsters);
 }
コード例 #6
0
ファイル: ServerBattle.cs プロジェクト: Relfos/MinimonServer
        public void ReceiveCommand(ServerPlayer p, ServerMessage msg)
        {
            byte opcode = msg.ReadByte();

                ServerBattleCommand cmd = null;

                switch (opcode) {
                case ServerBattle.opBattleAttack:
                        cmd = new BattleAttackCommand(p);
                        break;

                case ServerBattle.opBattleItem:
                        cmd = new BattleItemCommand(p);
                        break;

                case ServerBattle.opBattleSwitch:
                        cmd = new BattleSwitchCommand(p);
                        break;

                case ServerBattle.opBattleDefend:
                        cmd = new BattleDefendCommand(p);
                        break;

                case ServerBattle.opBattleCapture:
                    cmd = new BattleCaptureCommand(p);
                    break;

                default:
                    return;
            }

            cmd.Read(msg);
            this.AddCommand(cmd);

            actionTime = Utils.GetTickCount();
        }
コード例 #7
0
ファイル: ServerBattle.cs プロジェクト: Relfos/MinimonServer
        public void Cancel(ServerPlayer ignore, byte cancelReason)
        {
            if (this.finished)
                return;

            foreach (ServerPlayer player in _players)
            {
                ServerMessage msg = new ServerMessage(Protocol.netBattleCancel);
                msg.WriteByte(cancelReason);

                player.SendMessage(msg, 0);
                player.ClearBattles();
            }

            this.finished = true;
        }
コード例 #8
0
ファイル: ServerBattle.cs プロジェクト: Relfos/MinimonServer
 public void Broadcast(ServerMessage msg, ServerPlayer exclude)
 {
     foreach (ServerPlayer player in _players)
     if (player != exclude)
     {
         player.SendMessage(msg, 0);
     }
 }
コード例 #9
0
ファイル: ServerPlayer.cs プロジェクト: Relfos/MinimonServer
        public void ReceiveKeys(ServerMessage msg, GameSaveKeyType kind)
        {
            int count = msg.ReadWord();
            while (count>0) {
            string key = msg.ReadString();
            string value =  msg.ReadString();

            //Value := DecompressBinaryData(Value);
            this.UpdateKey(key, value, kind);

            count--;
            }
        }
コード例 #10
0
ファイル: Server.cs プロジェクト: Relfos/MinimonServer
 public void BroadcastToGuild(ServerMessage msg, UInt32 guildID, UInt32 owner)
 {
 }
コード例 #11
0
ファイル: ServerParty.cs プロジェクト: Relfos/MinimonServer
        public void RemovePlayer(ServerPlayer player)
        {
            for (int i = 0; i < Settings.MaxPartySize; i++)
            if (_members[i] == player)
            {
                _members[i] = null;
                player.party = null;
            }

            ServerMessage msg = new ServerMessage(Protocol.netSquadLeave);
            this.Broadcast(msg, player.accountID);

            if (this.GetMemberCount()<2) {
                msg = new ServerMessage(Protocol.netSquadDisband);
                this.Broadcast(msg, 0);
                msg = null;
            }
        }
コード例 #12
0
ファイル: ServerBattle.cs プロジェクト: Relfos/MinimonServer
        public void Update()
        {
            if (this.finished)
                return;

            if (this.loading)
            {
                if (Utils.GetTickCount() - loadTime > 1000 * 20)
                {
                    this.Cancel(null, ServerBattle.HashFailure);
                }

                return;
            }

            if (turnEnd)
            {
                foreach (ServerPlayer player in _players)
                {
                    if (player.turnState != BattleTurn.turnNext)
                        return;
                }

                turnEnd = false;

                byte state = BattleTurn.turnNext;

                foreach (ServerPlayer player in _players)
                {
                    ServerMessage msg = new ServerMessage(Protocol.netBattleTurn);
                    msg.WriteByte(state);
                    player.SendMessage(msg, 0);
                    player.turnState = BattleTurn.turnWaiting;
                }

                actionTime = Utils.GetTickCount();
                currentTurn = null;
                return;
            }

            if (currentTurn != null)
            {
                int result = currentTurn.Update();

                switch (result)
                {
                    case BattleTurn.turnTimeOut:
                        Utils.Log("Battle time out...", 0);
                        this.Cancel(null, winningSide);
                        return;

                    case BattleTurn.turnFinished:
                        _turns.Add(currentTurn);
                        actionTime = Utils.GetTickCount();

                        currentTurn.Finish();
                        turnEnd = true;
                        break;
                }

                if (Utils.GetTickCount() - actionTime > 1000 * 60 * 4)
                {
                    this.Cancel(null, ServerBattle.HashFailure);
                    return;
                }

            }
        }
コード例 #13
0
ファイル: ServerBattle.cs プロジェクト: Relfos/MinimonServer
 public override void Write(ServerMessage str)
 {
     base.Write(str);
     str.WriteInteger(moveID);
 }
コード例 #14
0
ファイル: ServerBattle.cs プロジェクト: Relfos/MinimonServer
        public override void Write(ServerMessage str)
        {
            base.Write(str);

            str.WriteByte(sourceTeam);
            str.WriteByte(sourceMonster);
        }
コード例 #15
0
ファイル: ServerBattle.cs プロジェクト: Relfos/MinimonServer
 public override void Read(ServerMessage str)
 {
     base.Read(str);
     switchIndex = str.ReadByte();
     resetStats = str.ReadByte();
     switchMsg = str.ReadString();
 }
コード例 #16
0
ファイル: ServerBattle.cs プロジェクト: Relfos/MinimonServer
        public override void Read(ServerMessage str)
        {
            base.Read(str);

            sourceTeam = str.ReadByte();
            sourceMonster = str.ReadByte();
        }
コード例 #17
0
ファイル: ServerPlayer.cs プロジェクト: Relfos/MinimonServer
        public void SendMessage(ServerMessage msg, UInt32 owner)
        {
            if (msg == null)
            return;

            if (!msg.Send(this.clientStream, owner))
            {
            this.shouldRemove = true;
            }
        }
コード例 #18
0
ファイル: Server.cs プロジェクト: Relfos/MinimonServer
 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);
 }
コード例 #19
0
ファイル: ServerBattle.cs プロジェクト: Relfos/MinimonServer
        public void SetPlayerReady(ServerPlayer p)
        {
            if (!loading)
                return;

            p.turnState = BattleTurn.turnWaiting;

            byte count = 0;
            foreach (ServerPlayer player in _players)
            if (player.turnState != BattleTurn.turnLoading)
            {
                count++;
            }

            if (count< this._players.Count)
                return;

            this.loading = false;

            // after sending info to everyone we let them start the battle
            foreach (ServerPlayer player in _players)
            {
                ServerMessage msg = new ServerMessage(Protocol.netBattleStart);
                msg.WriteByte(count); // player count
                msg.WriteByte(this.secondsPerTurn); // player timer
                msg.WriteByte(this.battleMode); // team index
                msg.WriteInteger(this.seed);
                msg.WriteByte(player.battleTeam); // team index
                msg.WriteByte(player.battleSide); // local side
                msg.WriteByte(player.monstersPerBattle);
                player.rules.Write(msg);

                player.SendMessage(msg, player.accountID);
            }
        }
コード例 #20
0
ファイル: ServerBattle.cs プロジェクト: Relfos/MinimonServer
        public virtual void SendTo(ServerPlayer player)
        {
            ServerMessage msg;

            if (player == null)
                return;

            msg = new ServerMessage(Protocol.netBattleCommand);
            this.Write(msg);
            player.SendMessage(msg, owner.accountID);
        }
コード例 #21
0
ファイル: ServerBattle.cs プロジェクト: Relfos/MinimonServer
        public void Start()
        {
            foreach (ServerPlayer p1 in _players)
            {
                p1.turnState = BattleTurn.turnLoading;

                foreach (ServerPlayer p2 in _players)
                {
                    if (p1 == p2)
                        continue;

                //Utils.Log("Sending opponent trainer info of " + p1.account.formattedPlayerName + " to " + p2.account.formattedPlayerName, 1);
                    ServerMessage msg = new ServerMessage(Protocol.netBattleTrainer);
                    msg.WriteByte(p1.battleTeam);
                    msg.WriteByte(p1.battleSide);
                    p2.SendMessage(msg, p1.accountID);
                }
            }

            // after sending info to everyone we let them start the battle
            foreach (ServerPlayer p1 in _players)
            {
                //Utils.Log("Sending battle start to " + p1.account.formattedPlayerName, 1);

                ServerMessage msg = new ServerMessage(Protocol.netBattleInit);
                p1.SendMessage(msg, p1.accountID);
            }
        }
コード例 #22
0
ファイル: Server.cs プロジェクト: Relfos/MinimonServer
        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();
        }
コード例 #23
0
ファイル: ServerBattle.cs プロジェクト: Relfos/MinimonServer
 public override void Read(ServerMessage str)
 {
     base.Read(str);
     moveID = str.ReadInteger();
 }
コード例 #24
0
ファイル: ServerBattle.cs プロジェクト: Relfos/MinimonServer
 public override void Write(ServerMessage str)
 {
     base.Write(str);
     str.WriteByte(switchIndex);
     str.WriteByte(resetStats);
     str.WriteString(switchMsg);
 }
コード例 #25
0
ファイル: ServerBattle.cs プロジェクト: Relfos/MinimonServer
 public virtual void Read(ServerMessage str)
 {
     index = str.ReadByte();
     turn = str.ReadInteger();
     priority = str.ReadInteger();
     speed = str.ReadInteger();
 }
コード例 #26
0
ファイル: ServerBattle.cs プロジェクト: Relfos/MinimonServer
        public override void Read(ServerMessage str)
        {
            base.Read(str);

            targetTeam = str.ReadByte();
            targetMonster = str.ReadByte();
        }
コード例 #27
0
ファイル: ServerBattle.cs プロジェクト: Relfos/MinimonServer
 public virtual void Write(ServerMessage str)
 {
     str.WriteByte(opcode);
     str.WriteByte(index);
     str.WriteInteger(turn);
     str.WriteInteger(priority);
     str.WriteInteger(speed);
 }
コード例 #28
0
ファイル: ServerBattle.cs プロジェクト: Relfos/MinimonServer
        public override void Write(ServerMessage str)
        {
            base.Write(str);

            str.WriteByte(targetTeam);
            str.WriteByte(targetMonster);
        }
コード例 #29
0
ファイル: ServerBattle.cs プロジェクト: Relfos/MinimonServer
        public bool Finish()
        {
            UInt32 currentHash = 0;

            foreach (ServerPlayer player in battle.Players)
            if (currentHash  == 0 || player.battleHash != currentHash)
            {
                this.battle.Cancel(null, ServerBattle.HashFailure);
                return true;
            } else
            {
                player.turnState = turnFinished;
            }

            foreach (ServerBattleCommand cmd in commands)
            {
                foreach (ServerPlayer player in battle.Players)
                if (player != cmd.owner)
                {
                    //Log(logConsole, 'Battle', 'Sending command to ' + CardinalToString(Battle.Players[J].accountID) + ' -> ' + cmd.ToString());
                    cmd.SendTo(player);
                }
            }

            // now tell everyone that the turn can be executed
            foreach (ServerPlayer player in battle.Players)
            {
                ServerMessage msg = new ServerMessage(Protocol.netBattleTurn);
                msg.WriteByte(turnFinished);
                player.SendMessage(msg, 0);
            }

              return false;
        }
コード例 #30
0
ファイル: ServerPlayer.cs プロジェクト: Relfos/MinimonServer
        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;
        }