TryGetPlayerState() public method

Look up the player state for a player in the internal lookup table.
public TryGetPlayerState ( uint PlayerObjectId ) : PlayerState
PlayerObjectId uint Supplies the PC object id to look up. ///
return PlayerState
        /// <summary>
        /// This method is called when the ClientEnter event fires for a
        /// player.  Its purpose is to check whether the player has a pending
        /// resync request, and, if so, to execute the resync operation.
        /// </summary>
        /// <param name="State">Supplies the player object of the incoming
        /// player.</param>
        /// <param name="Script">Supplies the script object.</param>
        public static void OnClientEnter(uint PCObject, ACR_ServerCommunicator Script)
        {
            PlayerState State = Script.TryGetPlayerState(PCObject);

            if (State == null)
            {
                return;
            }

            var ResyncInfo = (from RS in PlayerResyncStates
                              where RS.PlayerId == State.PlayerId
                              select RS).FirstOrDefault();

            if (ResyncInfo == null)
            {
                return;
            }

            //
            // Dequeue the resync state and start attempting to apply it to the
            // player object once the player has loaded.
            //

            PlayerResyncStates.Remove(ResyncInfo);
            ResynchronizePlayerState(ResyncInfo, PCObject, Script);
        }
        /// <summary>
        /// This method is called to resynchronize the GUI state of a player
        /// that executed a server to server portal, if the player is in an
        /// area.
        /// </summary>
        /// <param name="ResyncInfo">Supplies the resync block for the
        /// player.  This contains the deserialized resynchronization command
        /// data.</param>
        /// <param name="PCObject">Supplies the player object id.</param>
        /// <param name="Script">Supplies the script object.</param>
        /// <param name="Tries">Supplies the count of retries.</param>
        private static void ResynchronizePlayerState(ResyncState ResyncInfo, uint PCObject, ACR_ServerCommunicator Script, int Tries = 0)
        {
            if (Script.GetIsObjectValid(PCObject) == ACR_ServerCommunicator.FALSE)
            {
                //
                // The player logged out while a resync request was pending.
                // Throw away the state as it is no longer needed on a full log
                // out and log in sequence.
                //

                return;
            }

            if ((Script.GetArea(PCObject) == ACR_ServerCommunicator.OBJECT_INVALID) ||
                (Script.GetScriptHidden(PCObject) != ACR_ServerCommunicator.FALSE))
            {
                //
                // The player may still be in transition or is not yet loaded.
                // Queue the request.
                //

                if (Tries < MAX_RESYNC_RETRIES)
                {
                    Script.DelayCommand(RESYNC_RETRY_INTERVAL, delegate()
                    {
                        ResynchronizePlayerState(ResyncInfo, PCObject, Script, Tries + 1);
                    });
                }

                return;
            }

            PlayerState State = Script.TryGetPlayerState(PCObject);

            if (State == null)
            {
                return;
            }

            //
            // Area transition has finished.  Apply the GUI state now.
            //

            State.ChatSelectGUIExpanded = ((ResyncInfo.ResyncFlags & RESYNC_FLAG_CHAT_SELECT_EXPANDED) != 0);
            State.UpdateChatSelectGUIHeaders();

            Script.SendMessageToPC(PCObject, "Server to server portal completed.");
            Script.WriteTimestampedLogEntry(String.Format(
                                                "ACR_ServerCommunicator.GUIResynchronizer.ResynchronizePlayerState: Resynchronized player GUI state for player {0} after server-to-server portal.",
                                                Script.GetName(PCObject)));
        }
        /// <summary>
        /// Dispatch the event (in a script context).
        /// </summary>
        /// <param name="Script">Supplies the script object.</param>
        /// <param name="Database">Supplies the database connection.</param>
        public void DispatchEvent(ACR_ServerCommunicator Script, ALFA.Database Database)
        {
            //
            // If the event was for the local server, then don't re-broadcast
            // it.
            //

            if (Database.ACR_GetServerID() == Server.ServerId)
            {
                return;
            }

            string Message = String.Format(
                "<c=#FFFF00>Server {0} is now online.</c>",
                Server.Name);
            string ChatMessage = "</c>" + Message;

            foreach (uint PlayerObject in Script.GetPlayers(true))
            {
                PlayerState Player = Script.TryGetPlayerState(PlayerObject);

                if (Player == null)
                {
                    continue;
                }

                if (!Script.IsCrossServerNotificationEnabled(PlayerObject))
                {
                    continue;
                }

                if ((Player.Flags & PlayerStateFlags.SendCrossServerNotificationsToCombatLog) != 0)
                {
                    Script.SendMessageToPC(PlayerObject, Message);
                }
                else
                {
                    Script.SendChatMessage(
                        CLRScriptBase.OBJECT_INVALID,
                        PlayerObject,
                        CLRScriptBase.CHAT_MODE_SERVER,
                        ChatMessage,
                        CLRScriptBase.FALSE);
                }
            }

#if DEBUG_MODE
            Script.WriteTimestampedLogEntry(Message);
#endif
        }
        /// <summary>
        /// Dispatch the event (in a script context).
        /// </summary>
        /// <param name="Script">Supplies the script object.</param>
        /// <param name="Database">Supplies the database connection.</param>
        public void DispatchEvent(ACR_ServerCommunicator Script, ALFA.Database Database)
        {
            //
            // If the event was for the local server, then don't re-broadcast
            // it.
            //

            if (Database.ACR_GetServerID() == Server.ServerId)
                return;

            string Message = String.Format(
                "<c=#FFFF00>Server {0} is now offline.</c>",
                Server.Name);
            string ChatMessage = "</c>" + Message;

            foreach (uint PlayerObject in Script.GetPlayers(true))
            {
                PlayerState Player = Script.TryGetPlayerState(PlayerObject);

                if (Player == null)
                    continue;

                if (!Script.IsCrossServerNotificationEnabled(PlayerObject))
                    continue;

                if ((Player.Flags & PlayerStateFlags.SendCrossServerNotificationsToCombatLog) != 0)
                {
                    Script.SendMessageToPC(PlayerObject, Message);
                }
                else
                {
                    Script.SendChatMessage(
                        CLRScriptBase.OBJECT_INVALID,
                        PlayerObject,
                        CLRScriptBase.CHAT_MODE_SERVER,
                        ChatMessage,
                        CLRScriptBase.FALSE);
                }
            }

#if DEBUG_MODE
            Script.WriteTimestampedLogEntry(Message);
#endif
        }
        /// <summary>
        /// Dispatch the event (in a script context).
        /// </summary>
        /// <param name="Script">Supplies the script object.</param>
        /// <param name="Database">Supplies the database connection.</param>
        public void DispatchEvent(ACR_ServerCommunicator Script, ALFA.Database Database)
        {
            PlayerState State = Script.TryGetPlayerState(PlayerObject);
            string RequestURL;

            //
            // If the player is logged off, then there's nothing to do.
            //

            if (State == null || State.IsDM)
                return;

            if (String.IsNullOrEmpty(AccountAssociationSecret))
                return;

            RequestURL = AccountAssociator.GenerateAssociationURL(Script.GetPCPlayerName(PlayerObject), AccountAssociationSecret, AccountAssociationURL);

            Script.DisplayGuiScreen(PlayerObject, "acr_account_association", CLRScriptBase.FALSE, "acr_account_association.XML", CLRScriptBase.FALSE);
            Script.SetLocalGUIVariable(PlayerObject, "acr_account_association", 0, RequestURL);
        }
        /// <summary>
        /// Dispatch the event (in a script context).
        /// </summary>
        /// <param name="Script">Supplies the script object.</param>
        /// <param name="Database">Supplies the database connection.</param>
        public void DispatchEvent(ACR_ServerCommunicator Script, ALFA.Database Database)
        {
            PlayerState State = Script.TryGetPlayerState(PlayerObject);
            string      RequestURL;

            //
            // If the player is logged off, then there's nothing to do.
            //

            if (State == null || State.IsDM)
            {
                return;
            }

            if (String.IsNullOrEmpty(AccountAssociationSecret))
            {
                return;
            }

            RequestURL = AccountAssociator.GenerateAssociationURL(Script.GetPCPlayerName(PlayerObject), AccountAssociationSecret, AccountAssociationURL);

            Script.DisplayGuiScreen(PlayerObject, "acr_account_association", CLRScriptBase.FALSE, "acr_account_association.XML", CLRScriptBase.FALSE);
            Script.SetLocalGUIVariable(PlayerObject, "acr_account_association", 0, RequestURL);
        }
        /// <summary>
        /// Dispatch the event (in a script context).
        /// </summary>
        /// <param name="Script">Supplies the script object.</param>
        /// <param name="Database">Supplies the database connection.</param>
        public void DispatchEvent(ACR_ServerCommunicator Script, ALFA.Database Database)
        {
            //
            // If the event was for a player logging off of the local server,
            // then don't re-broadcast it.
            //

            foreach (uint PlayerObject in Script.GetPlayers(true))
            {
                PlayerState Player = Script.TryGetPlayerState(PlayerObject);

                if (Player == null)
                    continue;

                if (Player.CharacterIdsShown.Contains(Character.CharacterId))
                {
                    string sPlayerListBox = "";

                    if (Server.ServerId == Script.GetDatabase().ACR_GetServerID() || Script.GetLocalInt(PlayerObject, "chatselect_expanded") == 0)
                    {
                        if (IsDM == true)
                        {
                            sPlayerListBox = "LocalDMList";
                            Player.ChatSelectLocalDMsShown -= 1;
                        }
                        else
                        {
                            sPlayerListBox = "LocalPlayerList";
                            Player.ChatSelectLocalPlayersShown -= 1;
                        }
                    }
                    else
                    {
                        if (IsDM == true)
                        {
                            sPlayerListBox = "RemoteDMList";
                            Player.ChatSelectRemoteDMsShown -= 1;
                        }
                        else
                        {
                            sPlayerListBox = "RemotePlayerList";
                            Player.ChatSelectRemotePlayersShown -= 1;
                        }
                    }

                    Script.RemoveListBoxRow(Player.ObjectId, "ChatSelect", sPlayerListBox, Character.CharacterName);
                    Player.CharacterIdsShown.Remove(Character.CharacterId);
                    Player.UpdateChatSelectGUIHeaders();
                }
            }

            if (Database.ACR_GetServerID() == Server.ServerId)
                return;

            string Message = String.Format(
                "{0}<c=#FFDAB9>{1} ({2}) left {3}.</c>", // <c=Peachpuff...>
                IsDM ? "<c=#99CCFF>[DM] </c>" : "",
                Character.Name,
                Character.Player.Name,
                Server.Name);
            string ChatMessage = "</c>" + Message;

            foreach (uint PlayerObject in Script.GetPlayers(true))
            {
                PlayerState Player = Script.TryGetPlayerState(PlayerObject);

                if (Player == null)
                    continue;

                if (!Script.IsCrossServerNotificationEnabled(PlayerObject))
                    continue;

                if ((Player.Flags & PlayerStateFlags.SendCrossServerNotificationsToCombatLog) != 0)
                {
                    Script.SendMessageToPC(PlayerObject, Message);
                }
                else
                {
                    Script.SendChatMessage(
                        CLRScriptBase.OBJECT_INVALID,
                        PlayerObject,
                        CLRScriptBase.CHAT_MODE_SERVER,
                        ChatMessage,
                        CLRScriptBase.FALSE);
                }
            }

#if DEBUG_MODE
            Script.WriteTimestampedLogEntry(Message);
#endif
        }
        /// <summary>
        /// This method is called when a cross-server chat select
        /// resynchronization request is received.  Its purpose is to scan the
        /// player list to check whether the argument player is online, and to
        /// activate chat select GUI resynchronization if appropriate, else to
        /// queue the resynchronization until the player does log in.
        /// </summary>
        /// <param name="SourceServerId">Supplies the server id of the server
        /// that requested the GUI resynchronization.</param>
        /// <param name="ResyncCommand">Supplies the GUI resynchronizer command
        /// line as generated by SendGUIStateToServer().</param>
        /// <param name="Script">Supplies the current script object.</param>
        /// <returns>TRUE on success, else FALSE on failure.</returns>
        public static int HandleGUIResync(int SourceServerId, string ResyncCommand, ACR_ServerCommunicator Script)
        {
            try
            {
                ResyncState RemoteResyncInfo;

                //
                // Deserialize the remote resynchronization state.  On null, an
                // obviously invalid request was received.  Otherwise a protocol
                // violation that is atypical was received and an exception is
                // raised.
                //

                if ((RemoteResyncInfo = ResyncState.FromString(ResyncCommand)) == null)
                {
                    Script.WriteTimestampedLogEntry(String.Format(
                        "ACR_ServerCommunicator.GUIResynchronizer.HandleGUIResync({0}, {1}): Invalid request.",
                        SourceServerId,
                        ResyncCommand));
                    return ACR_ServerCommunicator.FALSE;
                }

                //
                // If a request was not already enqueued for this player, then
                // enqueue it.
                //

                var ResyncInfo = (from RS in PlayerResyncStates
                                  where RS.PlayerId == RemoteResyncInfo.PlayerId
                                  select RS).FirstOrDefault();

                if (ResyncInfo == null)
                {
                    //
                    // If the player is logged on, directly enqueue the execute
                    // request now.  Otherwise, wait for the ClientEnter event
                    // as the player might still reside on the remote server.
                    //

                    foreach (uint PCObject in Script.GetPlayers(true))
                    {
                        PlayerState State;

                        if ((State = Script.TryGetPlayerState(PCObject)) == null)
                            continue;

                        if (State.PlayerId != RemoteResyncInfo.PlayerId)
                            continue;

                        ResynchronizePlayerState(RemoteResyncInfo, PCObject, Script);

                        return ACR_ServerCommunicator.TRUE;
                    }

                    //
                    // Enqueue the request so that it can be processed at
                    // ClientEnter time.
                    //

                    PlayerResyncStates.Add(RemoteResyncInfo);
                }
                else
                {
                    //
                    // Update the resync flags to match the new request.
                    //

                    ResyncInfo.ResyncFlags = RemoteResyncInfo.ResyncFlags;
                }
            }
            catch (Exception e)
            {
                Script.WriteTimestampedLogEntry(String.Format(
                    "ACR_ServerCommunicator.GUIResynchronizer.HandleGUIResync({0}, {1}): Exception: {0}",
                    SourceServerId,
                    ResyncCommand,
                    e));
                return ACR_ServerCommunicator.FALSE;
            }

            return ACR_ServerCommunicator.TRUE;
        }
        /// <summary>
        /// This method is called to resynchronize the GUI state of a player
        /// that executed a server to server portal, if the player is in an
        /// area.
        /// </summary>
        /// <param name="ResyncInfo">Supplies the resync block for the
        /// player.  This contains the deserialized resynchronization command
        /// data.</param>
        /// <param name="PCObject">Supplies the player object id.</param>
        /// <param name="Script">Supplies the script object.</param>
        /// <param name="Tries">Supplies the count of retries.</param>
        private static void ResynchronizePlayerState(ResyncState ResyncInfo, uint PCObject, ACR_ServerCommunicator Script, int Tries = 0)
        {
            if (Script.GetIsObjectValid(PCObject) == ACR_ServerCommunicator.FALSE)
            {
                //
                // The player logged out while a resync request was pending.
                // Throw away the state as it is no longer needed on a full log
                // out and log in sequence.
                //

                return;
            }

            if ((Script.GetArea(PCObject) == ACR_ServerCommunicator.OBJECT_INVALID) ||
                (Script.GetScriptHidden(PCObject) != ACR_ServerCommunicator.FALSE))
            {
                //
                // The player may still be in transition or is not yet loaded.
                // Queue the request.
                //

                if (Tries < MAX_RESYNC_RETRIES)
                {
                    Script.DelayCommand(RESYNC_RETRY_INTERVAL, delegate()
                    {
                        ResynchronizePlayerState(ResyncInfo, PCObject, Script, Tries + 1);
                    });
                }

                return;
            }

            PlayerState State = Script.TryGetPlayerState(PCObject);

            if (State == null)
                return;

            //
            // Area transition has finished.  Apply the GUI state now.
            //

            State.ChatSelectGUIExpanded = ((ResyncInfo.ResyncFlags & RESYNC_FLAG_CHAT_SELECT_EXPANDED) != 0);
            State.UpdateChatSelectGUIHeaders();

            Script.SendMessageToPC(PCObject, "Server to server portal completed.");
            Script.WriteTimestampedLogEntry(String.Format(
                "ACR_ServerCommunicator.GUIResynchronizer.ResynchronizePlayerState: Resynchronized player GUI state for player {0} after server-to-server portal.",
                Script.GetName(PCObject)));
        }
        /// <summary>
        /// This method is called when the ClientEnter event fires for a
        /// player.  Its purpose is to check whether the player has a pending
        /// resync request, and, if so, to execute the resync operation.
        /// </summary>
        /// <param name="State">Supplies the player object of the incoming
        /// player.</param>
        /// <param name="Script">Supplies the script object.</param>
        public static void OnClientEnter(uint PCObject, ACR_ServerCommunicator Script)
        {
            PlayerState State = Script.TryGetPlayerState(PCObject);

            if (State == null)
                return;

            var ResyncInfo = (from RS in PlayerResyncStates
                              where RS.PlayerId == State.PlayerId
                              select RS).FirstOrDefault();

            if (ResyncInfo == null)
                return;

            //
            // Dequeue the resync state and start attempting to apply it to the
            // player object once the player has loaded.
            //

            PlayerResyncStates.Remove(ResyncInfo);
            ResynchronizePlayerState(ResyncInfo, PCObject, Script);
        }
        /// <summary>
        /// This method is called when a cross-server chat select
        /// resynchronization request is received.  Its purpose is to scan the
        /// player list to check whether the argument player is online, and to
        /// activate chat select GUI resynchronization if appropriate, else to
        /// queue the resynchronization until the player does log in.
        /// </summary>
        /// <param name="SourceServerId">Supplies the server id of the server
        /// that requested the GUI resynchronization.</param>
        /// <param name="ResyncCommand">Supplies the GUI resynchronizer command
        /// line as generated by SendGUIStateToServer().</param>
        /// <param name="Script">Supplies the current script object.</param>
        /// <returns>TRUE on success, else FALSE on failure.</returns>
        public static int HandleGUIResync(int SourceServerId, string ResyncCommand, ACR_ServerCommunicator Script)
        {
            try
            {
                ResyncState RemoteResyncInfo;

                //
                // Deserialize the remote resynchronization state.  On null, an
                // obviously invalid request was received.  Otherwise a protocol
                // violation that is atypical was received and an exception is
                // raised.
                //

                if ((RemoteResyncInfo = ResyncState.FromString(ResyncCommand)) == null)
                {
                    Script.WriteTimestampedLogEntry(String.Format(
                                                        "ACR_ServerCommunicator.GUIResynchronizer.HandleGUIResync({0}, {1}): Invalid request.",
                                                        SourceServerId,
                                                        ResyncCommand));
                    return(ACR_ServerCommunicator.FALSE);
                }

                //
                // If a request was not already enqueued for this player, then
                // enqueue it.
                //

                var ResyncInfo = (from RS in PlayerResyncStates
                                  where RS.PlayerId == RemoteResyncInfo.PlayerId
                                  select RS).FirstOrDefault();

                if (ResyncInfo == null)
                {
                    //
                    // If the player is logged on, directly enqueue the execute
                    // request now.  Otherwise, wait for the ClientEnter event
                    // as the player might still reside on the remote server.
                    //

                    foreach (uint PCObject in Script.GetPlayers(true))
                    {
                        PlayerState State;

                        if ((State = Script.TryGetPlayerState(PCObject)) == null)
                        {
                            continue;
                        }

                        if (State.PlayerId != RemoteResyncInfo.PlayerId)
                        {
                            continue;
                        }

                        ResynchronizePlayerState(RemoteResyncInfo, PCObject, Script);

                        return(ACR_ServerCommunicator.TRUE);
                    }

                    //
                    // Enqueue the request so that it can be processed at
                    // ClientEnter time.
                    //

                    PlayerResyncStates.Add(RemoteResyncInfo);
                }
                else
                {
                    //
                    // Update the resync flags to match the new request.
                    //

                    ResyncInfo.ResyncFlags = RemoteResyncInfo.ResyncFlags;
                }
            }
            catch (Exception e)
            {
                Script.WriteTimestampedLogEntry(String.Format(
                                                    "ACR_ServerCommunicator.GUIResynchronizer.HandleGUIResync({0}, {1}): Exception: {0}",
                                                    SourceServerId,
                                                    ResyncCommand,
                                                    e));
                return(ACR_ServerCommunicator.FALSE);
            }

            return(ACR_ServerCommunicator.TRUE);
        }
Example #12
0
        /// <summary>
        /// Dispatch the event (in a script context).
        /// </summary>
        /// <param name="Script">Supplies the script object.</param>
        /// <param name="Database">Supplies the database connection.</param>
        public void DispatchEvent(ACR_ServerCommunicator Script, ALFA.Database Database)
        {
            //
            // If the event was for a player logging on to the local server,
            // then don't re-broadcast it.
            //
            foreach (uint PlayerObject in Script.GetPlayers(true))
            {
                PlayerState Player = Script.TryGetPlayerState(PlayerObject);

                if (Player == null)
                {
                    continue;
                }

                if (!Player.CharacterIdsShown.Contains(Character.CharacterId))
                {
                    string sPlayerListBox = "";

                    if (Server.ServerId == Script.GetDatabase().ACR_GetServerID() || Script.GetLocalInt(PlayerObject, "chatselect_expanded") == 0)
                    {
                        if (IsDM == true)
                        {
                            sPlayerListBox = "LocalDMList";
                            Player.ChatSelectLocalDMsShown += 1;
                        }
                        else
                        {
                            sPlayerListBox = "LocalPlayerList";
                            Player.ChatSelectLocalPlayersShown += 1;
                        }

                        if (Server.ServerId == Script.GetDatabase().ACR_GetServerID())
                        {
                            Script.AddListBoxRow(Player.ObjectId, "ChatSelect", sPlayerListBox, Character.CharacterName, "RosterData=/t \"" + Character.CharacterName + "\"", "", "5=/t \"" + Character.CharacterName + "\" ", "");
                        }
                        else
                        {
                            if (Player.Flags.HasFlag(PlayerStateFlags.ChatSelectShowLocalPlayersOnlyWhenCollapsed))
                            {
                                continue;
                            }

                            Script.AddListBoxRow(Player.ObjectId, "ChatSelect", sPlayerListBox, Character.CharacterName, "RosterData=#t \"" + Character.CharacterName + "\"", "", "5=#t \"" + Character.CharacterName + "\" ", "");
                        }
                    }
                    else
                    {
                        if (IsDM == true)
                        {
                            sPlayerListBox = "RemoteDMList";
                            Player.ChatSelectRemoteDMsShown += 1;
                        }
                        else
                        {
                            sPlayerListBox = "RemotePlayerList";
                            Player.ChatSelectRemotePlayersShown += 1;
                        }

                        Script.AddListBoxRow(Player.ObjectId, "ChatSelect", sPlayerListBox, Character.CharacterName, "RosterData=#t \"" + Character.CharacterName + "\"", "", "5=#t \"" + Character.CharacterName + "\" ", "");
                    }

                    Player.CharacterIdsShown.Add(Character.CharacterId);
                    Player.UpdateChatSelectGUIHeaders();
                }
            }

            if (Database.ACR_GetServerID() == Server.ServerId)
            {
                return;
            }

            string Message = String.Format(
                "{0}<c=#FFA500>{1} ({2}) joined {3}.</c>", // <c=Orange...>
                IsDM ? "<c=#99CCFF>[DM] </c>": "",
                Character.Name,
                Character.Player.Name,
                Server.Name);
            string ChatMessage = "</c>" + Message;

            foreach (uint PlayerObject in Script.GetPlayers(true))
            {
                PlayerState Player = Script.TryGetPlayerState(PlayerObject);

                if (Player == null)
                {
                    continue;
                }

                if (!Script.IsCrossServerNotificationEnabled(PlayerObject))
                {
                    continue;
                }

                if ((Player.Flags & PlayerStateFlags.SendCrossServerNotificationsToCombatLog) != 0)
                {
                    Script.SendMessageToPC(PlayerObject, Message);
                }
                else
                {
                    Script.SendChatMessage(
                        CLRScriptBase.OBJECT_INVALID,
                        PlayerObject,
                        CLRScriptBase.CHAT_MODE_SERVER,
                        ChatMessage,
                        CLRScriptBase.FALSE);
                }
            }

#if DEBUG_MODE
            Script.WriteTimestampedLogEntry(Message);
#endif
        }