Exemplo n.º 1
0
        public bool SetGuildDescription(string characterID, string guildID, string description)
        {
            DbObjectWrapper <Guild> guild = null;

            if (!mCache.TryGetGuild(guildID, out guild))
            {
                log.Info("SetGuildDescription - guild not found");
                return(false);
            }

            GuildMember member = null;

            if (!guild.Data.TryGetMember(characterID, out member))
            {
                log.Info("SetGuildDescription - member not found");
                return(false);
            }

            if (!member.IsSetGuildDescriptionGranted())
            {
                log.Info("SetGuildDescription - set description not allowed");
                return(false);
            }

            guild.Data.description = description;
            guild.Changed          = true;
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Set guild for player character
        /// </summary>
        public void SetGuild(string gameRefID, string characterID, string guildID)
        {
            DbObjectWrapper <DbPlayerCharactersObject> player = GetExistingPlayer(gameRefID);

            if (player == null)
            {
                log.InfoFormat("plaer = {0} not exists", gameRefID);
                return;
            }

            player.Data.SetGuild(characterID, guildID);
            player.Changed = true;

            SelectCharacterClientPeer peer = null;

            if (mApplication.Clients.TryGetPeerForGameRefId(player.Data.GameRefId, out peer))
            {
                if (peer != null)
                {
                    CharacterUpdateEvent evt = new CharacterUpdateEvent {
                        Characters = player.Data.GetInfo()
                    };
                    EventData eventData = new EventData((byte)SelectCharacterEventCode.CharactersUpdate, evt);
                    peer.SendEvent(eventData, new SendParameters());
                }
            }
        }
Exemplo n.º 3
0
        public void SetChanged(string characterId, bool changed)
        {
            DbObjectWrapper <CharacterNotifications> notification = null;

            if (cache.TryGetValue(characterId, out notification))
            {
                notification.Changed = changed;
            }
        }
Exemplo n.º 4
0
        public DbObjectWrapper <DbPlayerCharactersObject> GetCachePlayerByCharacterName(string characterName)
        {
            DbObjectWrapper <DbPlayerCharactersObject> player = null;

            if (mCache.TryGetPlayerBySelectedCharacterName(characterName, out player))
            {
                return(player);
            }
            return(null);
        }
Exemplo n.º 5
0
        public void ForceSave(string characterId, MongoCollection <CharacterNotifications> collection)
        {
            DbObjectWrapper <CharacterNotifications> notification = null;

            if (cache.TryGetValue(characterId, out notification))
            {
                collection.Save(notification.Data);
                notification.Changed = false;
            }
        }
Exemplo n.º 6
0
        private void SendCharacterUpdateToClient(DbObjectWrapper <DbPlayerCharactersObject> player)
        {
            GenericEvent eventInstance = new GenericEvent {
                subCode = (int)SelectCharacterGenericEventSubCode.CharactersUpdate,
                data    = player.Data.GetInfo()
            };
            EventData eventData = new EventData((byte)SelectCharacterEventCode.GenericEvent, eventInstance);

            mApplication.SendEventToClient(player.Data.GameRefId, eventData);
        }
Exemplo n.º 7
0
        public void SetChanged(string gameRefId, bool changed)
        {
            DbObjectWrapper <DbPlayerCharactersObject> wrapper = null;

            lock (syncObject) {
                if (TryGetValue(gameRefId, out wrapper))
                {
                    wrapper.Changed = changed;
                }
            }
        }
Exemplo n.º 8
0
        public bool TryGetNotification(string characterId, out CharacterNotifications notification)
        {
            DbObjectWrapper <CharacterNotifications> wrapper = null;

            if (cache.TryGetValue(characterId, out wrapper))
            {
                notification = wrapper.Data;
                return(true);
            }
            notification = null;
            return(false);
        }
Exemplo n.º 9
0
 public bool TryGetPlayerByCharacterId(string characterId, out DbObjectWrapper <DbPlayerCharactersObject> result)
 {
     result = null;
     lock (syncObject) {
         foreach (var pair in this)
         {
             if (pair.Value.Data.HasCharacter(characterId))
             {
                 result = pair.Value;
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 10
0
        public bool ChangeGuildStatus(string guildID, bool opened)
        {
            DbObjectWrapper <Guild> guild = null;

            if (!mCache.TryGetGuild(guildID, out guild))
            {
                log.InfoFormat("ChangeGuildStatus: guild not found [green]");
                return(false);
            }
            guild.Data.SetOpened(opened);
            guild.Changed = true;
            SendGuildUpdateEvent(guildID, guild.Data.GetInfo(mApplication));
            log.InfoFormat("ChangeGuildStatus: guils status changed to = {0} [green]", opened);
            return(true);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Delete character from player
        /// </summary>
        /// <param name="gameRefId">id of player</param>
        /// <param name="characterId">id of character</param>
        /// <returns></returns>
        public bool RemovePlayerCharacter(string gameRefId, string characterId)
        {
            DbObjectWrapper <DbPlayerCharactersObject> wrapper = null;

            lock (syncObject) {
                if (TryGetValue(gameRefId, out wrapper))
                {
                    if (wrapper.Data.DeleteCharacter(characterId))
                    {
                        wrapper.Changed = true;
                        return(true);
                    }
                }
                return(false);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Update model, world and exp for character in collection( if present in collection)
        /// </summary>
        /// <param name="gameRefId">id of player</param>
        /// <param name="characterId">id of character</param>
        /// <param name="model">ship model hash</param>
        /// <param name="worldId">current world</param>
        /// <param name="exp">current exp</param>
        public void UpdatePlayerCharacterObject(string gameRefId, string characterId, Dictionary <ShipModelSlotType, string> model, string worldId, int exp)
        {
            DbObjectWrapper <DbPlayerCharactersObject> wrapper = null;

            lock (syncObject) {
                if (TryGetValue(gameRefId, out wrapper))
                {
                    if (wrapper.Data == null)
                    {
                        log.Error("Wrapper data is null");
                        return;
                    }
                    wrapper.Data.UpdateModel(characterId, model, worldId, exp);
                    wrapper.Changed = true;
                }
            }
        }
Exemplo n.º 13
0
        public bool TryGetPlayerByLogin(string inlogin, out DbObjectWrapper <DbPlayerCharactersObject> result)
        {
            string login = inlogin.ToLower();

            result = null;
            lock (syncObject) {
                foreach (var pair in this)
                {
                    if (pair.Value.Data.Login.ToLower() == login)
                    {
                        result = pair.Value;
                        return(true);
                    }
                }
                return(false);
            }
        }
Exemplo n.º 14
0
        public Guild GetGuild(string ownerCharacterId)
        {
            DbObjectWrapper <Guild> wrapperGuild = null;

            if (mCache.TryGetGuild(ownerCharacterId, out wrapperGuild))
            {
                return(wrapperGuild.Data);
            }

            var guild = mApplication.DB.Guilds.FindOne(Query <Guild> .EQ(g => g.ownerCharacterId, ownerCharacterId));

            if (guild != null)
            {
                mCache.SetGuild(guild);
            }
            return(guild);
        }
Exemplo n.º 15
0
        public void UpdateShipModel(string gameRefID, string characterID, ShipModelSlotType slotType, string templateID)
        {
            DbObjectWrapper <DbPlayerCharactersObject> wrapper = null;

            lock (syncObject) {
                if (TryGetValue(gameRefID, out wrapper))
                {
                    if (wrapper.Data.SelectedCharacterId == characterID)
                    {
                        var character = wrapper.Data.GetCharacter(characterID);
                        if (character != null)
                        {
                            character.SetModule((byte)slotType, templateID);
                            wrapper.Changed = true;
                        }
                    }
                }
            }
        }
Exemplo n.º 16
0
        public void SetNotification(CharacterNotifications notification)
        {
            bool success = true;

            if (cache.ContainsKey(notification.characterId))
            {
                DbObjectWrapper <CharacterNotifications> oldNotification = null;
                if (!cache.TryRemove(notification.characterId, out oldNotification))
                {
                    success = false;
                }
            }

            if (success)
            {
                cache.TryAdd(notification.characterId, new DbObjectWrapper <CharacterNotifications> {
                    Changed = true, Data = notification
                });
            }
        }
Exemplo n.º 17
0
        public DbObjectWrapper <DbPlayerCharactersObject> GetExistingPlayerByLogin(string login)
        {
            DbObjectWrapper <DbPlayerCharactersObject> player = null;

            if (mCache.TryGetPlayerByLogin(login, out player))
            {
                return(player);
            }
            var playerFromDB = mApplication.DB.GetByLogin(login);

            if (playerFromDB != null)
            {
                mCache.SetPlayerCharactersObject(playerFromDB.GameRefId, playerFromDB);
                if (mCache.TryGetValue(playerFromDB.GameRefId, out player))
                {
                    return(player);
                }
            }
            player = null;
            return(player);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Return existing player from cache or database without creating new player
        /// </summary>
        public DbObjectWrapper <DbPlayerCharactersObject> GetExistingPlayer(string gameRefID)
        {
            DbObjectWrapper <DbPlayerCharactersObject> player = null;

            if (mCache.TryGetValue(gameRefID, out player))
            {
                return(player);
            }
            var playerFromDB = mApplication.DB.Get(gameRefID);

            if (playerFromDB != null)
            {
                mCache.SetPlayerCharactersObject(gameRefID, playerFromDB);
                if (mCache.TryGetValue(gameRefID, out player))
                {
                    return(player);
                }
            }
            player = null;
            return(player);
        }
Exemplo n.º 19
0
        public DbObjectWrapper <PlayerFriends> GetFriendsObject(string gameRefID, string login)
        {
            DbObjectWrapper <PlayerFriends> data = null;

            if (mCache.TryGetPlayerFriends(gameRefID, out data))
            {
                return(data);
            }

            var dbFriends = application.DB.friends.FindOne(Query <PlayerFriends> .EQ(f => f.gameRefID, gameRefID));

            if (dbFriends != null)
            {
                if (mCache.TryAddPlayerFriends(dbFriends))
                {
                    if (mCache.TryGetPlayerFriends(gameRefID, out data))
                    {
                        return(data);
                    }
                }
            }
            else
            {
                PlayerFriends newFriends = new PlayerFriends {
                    gameRefID = gameRefID, login = login, friends = new Dictionary <string, Friend>()
                };
                application.DB.friends.Save(newFriends);
                if (mCache.TryAddPlayerFriends(newFriends))
                {
                    if (mCache.TryGetPlayerFriends(gameRefID, out data))
                    {
                        return(data);
                    }
                }
            }
            data = null;
            return(null);
        }
Exemplo n.º 20
0
        public bool SelectCharacter(string gameRefId, string characterId, out DbPlayerCharactersObject playerObject)
        {
            playerObject = null;
            DbObjectWrapper <DbPlayerCharactersObject> wrapper = null;

            lock (syncObject) {
                if (TryGetValue(gameRefId, out wrapper))
                {
                    var selectedCharacter = wrapper.Data.SelectCharacter(characterId);
                    if (selectedCharacter == null)
                    {
                        return(false);
                    }
                    else
                    {
                        wrapper.Changed = true;
                        playerObject    = wrapper.Data;
                        return(true);
                    }
                }
                return(false);
            }
        }
Exemplo n.º 21
0
        public void SetGuild(string characterId, string guildId)
        {
            DbObjectWrapper <DbPlayerCharactersObject> player = null;

            if (mCache.TryGetPlayerByCharacterId(characterId, out player))
            {
                player.Data.SetGuild(characterId, guildId);
                player.Changed = true;

                SelectCharacterClientPeer peer = null;
                if (mApplication.Clients.TryGetPeerForGameRefId(player.Data.GameRefId, out peer))
                {
                    if (peer != null)
                    {
                        CharacterUpdateEvent evt = new CharacterUpdateEvent {
                            Characters = player.Data.GetInfo()
                        };
                        EventData eventData = new EventData((byte)SelectCharacterEventCode.CharactersUpdate, evt);
                        peer.SendEvent(eventData, new SendParameters());
                    }
                }
            }
        }
Exemplo n.º 22
0
 public bool TryGetPlayerFriends(string gameRefID, out DbObjectWrapper <PlayerFriends> friends)
 {
     return(mCachedFriends.TryGetValue(gameRefID, out friends));
 }
Exemplo n.º 23
0
        /// <summary>
        /// Changing status of member by other member
        /// </summary>
        /// <param name="sourceCharacterID">Character ID of member who make changes</param>
        /// <param name="targetCharacterID">Character ID of membe who will be changed</param>
        /// <param name="guildID">Target guild id</param>
        /// <param name="status">New status of member</param>
        /// <returns></returns>
        public bool ChangeGuildMemberStatus(string sourceCharacterID, string targetCharacterID, string guildID, int status)
        {
            if (sourceCharacterID == targetCharacterID)
            {
                log.Info("ChangeGuildMemberStatus - don't allow change self status");
                return(false);
            }

            DbObjectWrapper <Guild> guild = null;

            if (!mCache.TryGetGuild(guildID, out guild))
            {
                log.Info("ChangeGuildMemberStatus - guild not found");
                return(false);
            }

            GuildMember sourceMember = null;

            if (!guild.Data.TryGetMember(sourceCharacterID, out sourceMember))
            {
                log.Info("ChangeGuildMemberStatus - source member not found");
                return(false);
            }

            GuildMember targetMember = null;

            if (!guild.Data.TryGetMember(targetCharacterID, out targetMember))
            {
                log.Info("ChangeGuildMemberStatus - target member not found");
                return(false);
            }

            GuildMemberStatus newStatus = (GuildMemberStatus)status;

            if (newStatus == GuildMemberStatus.Moderator)
            {
                if (!guild.Data.addingModersAllowed)
                {
                    log.InfoFormat("ChangeGuildMemberStatus: guild already has maximum count of moderators [green]");
                    return(false);
                }
            }

            GuildMemberStatus sourceStatus = (GuildMemberStatus)sourceMember.guildStatus;
            GuildMemberStatus targetStatus = (GuildMemberStatus)targetMember.guildStatus;


            if (sourceStatus == GuildMemberStatus.Moderator)
            {
                if (targetStatus != GuildMemberStatus.Member)
                {
                    log.Info("ChangeGuildMemberStatus - moderator allow change only members status");
                    return(false);
                }
                if (newStatus != GuildMemberStatus.Moderator)
                {
                    log.Info("ChangeGuildMemberStatus - moderator allow raise status of member to moderator only");
                    return(false);
                }
            }
            else if (sourceStatus == GuildMemberStatus.Owner)
            {
                if (targetStatus == GuildMemberStatus.Owner)
                {
                    log.Info("ChangeGuildMemberStatus  - Don't allow two owners of guild");
                    return(false);
                }
                if (newStatus == targetStatus)
                {
                    log.Info("ChangeGuildMemberStatus - New status same as before status");
                    return(false);
                }
            }

            targetMember.guildStatus = status;
            guild.Changed            = true;

            if (status == (int)GuildMemberStatus.Moderator)
            {
                guild.Data.AddTransaction(CoalitionTransaction.MakeTransaction(CoalitionTransactionType.make_officier, string.Empty, string.Empty, targetMember.characterName, targetMember.characterId));
            }

            SendGuildUpdateEvent(sourceMember.characterId, guild.Data.GetInfo(mApplication));
            SendGuildUpdateEvent(targetMember.characterId, guild.Data.GetInfo(mApplication));

            if (newStatus == GuildMemberStatus.Moderator)
            {
                mApplication.AddAchievmentVariable(targetMember.gameRefId, "coalition_officier", 1);
            }
            return(true);
        }
Exemplo n.º 24
0
 public bool TryGetGuild(string ownerCharacterId, out DbObjectWrapper <Guild> guild)
 {
     return(mGuilds.TryGetValue(ownerCharacterId, out guild));
 }
Exemplo n.º 25
0
 public bool TryGetWrapper(string characterId, out DbObjectWrapper <CharacterNotifications> notification)
 {
     return(cache.TryGetValue(characterId, out notification));
 }