Ejemplo n.º 1
0
            private static void ServerLoadSystem()
            {
                var database = Server.Database;

                if (!database.TryGet(nameof(ChatSystem),
                                     DatabaseKeyGlobalChatRoomHolder,
                                     out sharedGlobalChatRoomHolder))
                {
                    sharedGlobalChatRoomHolder = ServerCreateChatRoom(new ChatRoomGlobal());
                    database.Set(nameof(ChatSystem), DatabaseKeyGlobalChatRoomHolder, sharedGlobalChatRoomHolder);
                }

                if (!database.TryGet(nameof(ChatSystem),
                                     DatabaseKeyLocalChatRoomHolder,
                                     out sharedLocalChatRoomHolder))
                {
                    sharedLocalChatRoomHolder = ServerCreateChatRoom(new ChatRoomLocal());
                    database.Set(nameof(ChatSystem), DatabaseKeyLocalChatRoomHolder, sharedLocalChatRoomHolder);
                }

                // right now it's not possible to enumerate all the existing chat rooms as this is a bootstrapper
                // schedule a delayed initialization
                ServerTimersSystem.AddAction(
                    0.1,
                    () =>
                {
                    foreach (var chatRoomHolder in ServerWorld
                             .GetGameObjectsOfProto <ILogicObject, ChatRoomHolder>()
                             .ToList())
                    {
                        if (!(SharedGetChatRoom(chatRoomHolder) is ChatRoomPrivate privateChatRoom))
                        {
                            continue;
                        }

                        var characterA = Server.Characters.GetPlayerCharacter(privateChatRoom.CharacterA);
                        var characterB = Server.Characters.GetPlayerCharacter(privateChatRoom.CharacterB);

                        if (characterA == null ||
                            characterB == null)
                        {
                            // incorrect private chat room
                            ServerWorld.DestroyObject(chatRoomHolder);
                            continue;
                        }

                        ServerAddPrivateChatRoomToCharacterCache(characterA, chatRoomHolder);
                        ServerAddPrivateChatRoomToCharacterCache(characterB, chatRoomHolder);
                    }