コード例 #1
0
        public void CheckExecutableServerCommands(int endSubTick, LogicArrayList <LogicCommand> commands)
        {
            for (int i = 0; i < commands.Size(); i++)
            {
                LogicCommand command = commands[i];

                if (command.IsServerCommand())
                {
                    if (this.m_logicGameMode.GetState() != 1)
                    {
                        commands.Remove(i--);
                        continue;
                    }

                    LogicServerCommand serverCommand         = (LogicServerCommand)command;
                    LogicServerCommand bufferedServerCommand = null;

                    for (int j = 0; j < this.m_bufferedServerCommands.Size(); j++)
                    {
                        LogicServerCommand tmp = this.m_bufferedServerCommands[j];

                        if (tmp.GetId() == serverCommand.GetId())
                        {
                            bufferedServerCommand = tmp;
                        }
                    }

                    if (bufferedServerCommand == null || bufferedServerCommand.GetCommandType() != serverCommand.GetCommandType() ||
                        bufferedServerCommand.GetExecuteSubTick() != -1 && bufferedServerCommand.GetExecuteSubTick() >= this.m_logicGameMode.GetLevel().GetLogicTime().GetTick())
                    {
                        commands.Remove(i--);
                        continue;
                    }

                    bufferedServerCommand.SetExecuteSubTick(serverCommand.GetExecuteSubTick());
                    commands[i] = bufferedServerCommand;
                }
            }
        }
コード例 #2
0
        private static void OnHomeStateCallbackMessageReceived(GameStateCallbackMessage message)
        {
            if (GameAvatarManager.TryGet(message.AccountId, out GameAvatar gameDocument))
            {
                gameDocument.LogicClientAvatar = message.LogicClientAvatar;

                if (message.HomeJSON != null)
                {
                    for (int i = 0; i < message.ExecutedServerCommands.Size(); i++)
                    {
                        LogicServerCommand serverCommand = message.ExecutedServerCommands[i];

                        for (int j = 0; j < gameDocument.ServerCommands.Size(); j++)
                        {
                            if (gameDocument.ServerCommands[j].GetId() == serverCommand.GetId())
                            {
                                gameDocument.ServerCommands.Remove(j);
                                break;
                            }
                        }
                    }

                    gameDocument.LogicClientHome.GetCompressibleHomeJSON().Set(message.HomeJSON);
                    gameDocument.LogicClientHome.SetShieldDurationSeconds(message.RemainingShieldTime);
                    gameDocument.LogicClientHome.SetGuardDurationSeconds(message.RemainingGuardTime);
                    gameDocument.LogicClientHome.SetPersonalBreakSeconds(message.NextPersonalBreakTime);
                    gameDocument.SaveTime = message.SaveTime;
                }

                if (gameDocument.LogicClientAvatar.IsInAlliance() && message.AvatarChanges.Size() != 0)
                {
                    ServerMessageManager.SendMessage(new AllianceAvatarChangesMessage
                    {
                        AccountId     = gameDocument.LogicClientAvatar.GetAllianceId(),
                        MemberId      = gameDocument.LogicClientAvatar.GetId(),
                        AvatarChanges = message.AvatarChanges
                    }, 11);
                }

                GameSession currentSession = gameDocument.CurrentSession;

                if (currentSession != null)
                {
                    DateTime utc = DateTime.UtcNow;

                    if (utc.Subtract(currentSession.LastDbSave).TotalSeconds > 2)
                    {
                        GameAvatarManager.Save(gameDocument);
                        currentSession.LastDbSave = utc;
                    }

                    if (message.SessionId != currentSession.Id)
                    {
                        currentSession.SendPiranhaMessage(new OutOfSyncMessage(), 1);
                        currentSession.SendMessage(new StopSessionMessage {
                            Reason = 1
                        }, 1);
                        return;
                    }

                    if (message.AvatarChanges.Size() != 0)
                    {
                        for (int i = 0; i < message.AvatarChanges.Size(); i++)
                        {
                            if (message.AvatarChanges[i].GetAvatarChangeType() == AvatarChangeType.ALLIANCE_JOINED)
                            {
                                currentSession.BindAllianceServer();
                            }
                        }
                    }
                }
                else
                {
                    GameAvatarManager.Save(gameDocument);
                }
            }
        }