Esempio n. 1
0
        public bool Execute(JHSNetworkMessage netMsg)
        {
            if (DbManager == null)
            {
                DbManager = AccountManager.Instance;
            }

            ExchangeCur packet = netMsg.ReadMessage <ExchangeCur>();

            if (packet != null)
            {
                uint       connectionId = netMsg.conn.connectionId;
                AccountOBJ user         = DbManager.GetOnlineByConnectionId(connectionId);
                if (user != null)
                {
                    switch (packet.CurencyType)
                    {
                    case 0:    // SILVER TO GOLD
                        lock (user)
                        {
                            int Total = (int)packet.Value * Settings.SILVER_EXCAHNGE_RATE;
                            if (user.Silver < packet.Value)
                            {
                                netMsg.conn.Send(NetworkConstants.EXCHANGE, new ExchangeCurResp()
                                {
                                    STATUS = NOT_ENOUGH_SILVER
                                });
                                return(true);
                            }
                            user.Silver -= (int)packet.Value;
                            user.Gold   += Total;
                            DbService.SubmitUpdate2Queue(user);
                            user.ResetNotification();
                            netMsg.conn.Send(NetworkConstants.EXCHANGE, new ExchangeCurResp()
                            {
                                STATUS = SUCCESS, SilverValue = (uint)user.Silver, GoldValue = (uint)user.Gold
                            });
                            return(true);
                        }

                    case 1:    // GOLD TO SILVER
                        lock (user)
                        {
                            int Total = (int)packet.Value * Settings.GOLD_EXCAHNGE_RATE;
                            if (user.Gold < packet.Value)
                            {
                                netMsg.conn.Send(NetworkConstants.EXCHANGE, new ExchangeCurResp()
                                {
                                    STATUS = NOT_ENOUGH_GOLD
                                });
                                return(true);
                            }
                            user.Gold   -= (int)packet.Value;
                            user.Silver += Total;
                            user.ResetNotification();
                            DbService.SubmitUpdate2Queue(user);
                            netMsg.conn.Send(NetworkConstants.EXCHANGE, new ExchangeCurResp()
                            {
                                STATUS = SUCCESS, SilverValue = (uint)user.Silver, GoldValue = (uint)user.Gold
                            });
                            return(true);
                        }
                    }
                }
                else
                {
                    //DO NOTHING
                    return(true);
                }
            }
            return(true);
        }
        public bool Execute(JHSNetworkMessage netMsg)
        {
            if (DbManager == null)
            {
                DbManager = AccountManager.Instance;
            }

            CollectActive packet = netMsg.ReadMessage <CollectActive>();

            if (packet != null)
            {
                uint       connectionId = netMsg.conn.connectionId;
                AccountOBJ user         = DbManager.GetOnlineByConnectionId(connectionId);
                if (user != null)
                {
                    lock (user)
                    {
                        ActivesConfig model = ConfigManager.GetActive((int)packet.AciveId);
                        if (model == null)
                        {
                            netMsg.conn.Send(NetworkConstants.COLLECT_ACTIVE, new CollectActiveResponse()
                            {
                                STATUS = ITEM_CONFIG_WRONG
                            });
                            return(true);
                        }

                        ActivesOBJ active = user.GetActive((int)packet.AciveId);
                        if (active == null)
                        {
                            netMsg.conn.Send(NetworkConstants.COLLECT_ACTIVE, new CollectActiveResponse()
                            {
                                STATUS = ACTIVE_NOT_FOUND
                            });
                            return(true);
                        }

                        if (active.Collected)
                        {
                            netMsg.conn.Send(NetworkConstants.COLLECT_ACTIVE, new CollectActiveResponse()
                            {
                                STATUS = ACTIVE_ALREADY_COLLECTED
                            });
                            return(true);
                        }
                        if (model.Conditions != active.Value)
                        {
                            netMsg.conn.Send(NetworkConstants.COLLECT_ACTIVE, new CollectActiveResponse()
                            {
                                STATUS = ACTIVE_NOT_COMPLEATED
                            });
                            return(true);
                        }

                        active.Collected = true;
                        DbService.SubmitUpdate2Queue(active);

                        if (model.GoldReward > 0)
                        {
                            user.Gold += model.GoldReward;
                        }

                        if (model.SilverReward > 0)
                        {
                            user.Silver += model.SilverReward;
                        }

                        user.ResetNotification();
                        DbService.SubmitUpdate2Queue(user);

                        netMsg.conn.Send(NetworkConstants.COLLECT_ACTIVE, new CollectActiveResponse()
                        {
                            STATUS = SUCCESS, AciveId = packet.AciveId, Gold = (uint)user.Gold, Silver = (uint)user.Silver
                        });
                    }
                }
            }
            return(true);
        }
        public bool Execute(JHSNetworkMessage netMsg)
        {
            if (DbManager == null)
            {
                DbManager = AccountManager.Instance;
            }

            DeleteCharacter packet = netMsg.ReadMessage <DeleteCharacter>();

            if (packet != null)
            {
                uint       connectionId = netMsg.conn.connectionId;
                AccountOBJ user         = DbManager.GetOnlineByConnectionId(connectionId);
                if (user != null)
                {
                    lock (user)
                    {
                        if (user.Skins.Count <= 1)
                        {
                            netMsg.conn.Send(NetworkConstants.DELETE_CHARACTER, new DeleteCharacterResponse()
                            {
                                STATUS = NOT_DELETE_LAST_CHARACTER
                            });
                            return(true);
                        }
                        CharacterOBJ character = user.GetPlayer(packet.PlayerId);
                        if (character != null)
                        {
                            ConfiModel model = ConfigManager.GetModel(character.SkinId);
                            if (model == null)
                            {
                                netMsg.conn.Send(NetworkConstants.DELETE_CHARACTER, new DeleteCharacterResponse()
                                {
                                    STATUS = ITEM_CONFIG_WRONG
                                });
                                return(true);
                            }
                            uint playerId = character.PlayerId;
                            if (DbService.RemoveEntity(character.GetEntity()) && user.Skins.Remove(playerId))
                            {
                                user.Silver += model.SilverPrice;
                                user.ResetNotification();
                                DbService.SubmitUpdate2Queue(user);
                                netMsg.conn.Send(NetworkConstants.DELETE_CHARACTER, new DeleteCharacterResponse()
                                {
                                    STATUS = SUCCESS, PlayerId = playerId, Gold = (uint)user.Gold, Silver = (uint)user.Silver
                                });
                            }
                            else
                            {
                                netMsg.conn.Send(NetworkConstants.DELETE_CHARACTER, new DeleteCharacterResponse()
                                {
                                    STATUS = PLAYER_NOT_FOUND
                                });
                            }
                        }
                        else
                        {
                            netMsg.conn.Send(NetworkConstants.DELETE_CHARACTER, new DeleteCharacterResponse()
                            {
                                STATUS = PLAYER_NOT_FOUND
                            });
                        }
                    }
                }
            }
            return(true);
        }
Esempio n. 4
0
        public bool Execute(JHSNetworkMessage netMsg)
        {
            if (DbManager == null)
            {
                DbManager = AccountManager.Instance;
            }

            if (matchQueue == null)
            {
                matchQueue = PlayerQueueManager.Instance;
            }

            SearchMatch packet = netMsg.ReadMessage <SearchMatch>();

            if (packet != null)
            {
                uint       connectionId = netMsg.conn.connectionId;
                AccountOBJ user         = DbManager.GetOnlineByConnectionId(connectionId);
                if (user != null)
                {
                    switch (packet.op)
                    {
                    case SearchMatchOperations.Search:
                        if (user.InQueue)
                        {
                            netMsg.conn.Send(NetworkConstants.START_SEARCH_MATCH, new SearchMatch()
                            {
                                op = SearchMatchOperations.NO_ERROR_SEARCHING
                            });
                            return(true);
                        }
                        CharacterOBJ player = user.GetPlayer(packet.value);
                        if (player != null)
                        {
                            lock (user)
                            {
                                user.SelectedCharacer = player.PlayerId;
                                user.InQueue          = true;
                                user.ResetNotification();
                                matchQueue.AddPlayer(new MatchPlayer()
                                {
                                    League = user.League, userId = user.Id, ConnectionId = connectionId, PlayerId = player.PlayerId
                                });
                                netMsg.conn.Send(NetworkConstants.START_SEARCH_MATCH, new SearchMatch()
                                {
                                    op = SearchMatchOperations.SEARCHING_INIT, value = (uint)matchQueue.AvregeWaitTime()
                                });
                            }
                        }
                        else
                        {
                            netMsg.conn.Send(NetworkConstants.START_SEARCH_MATCH, new SearchMatch()
                            {
                                op = SearchMatchOperations.ERR_CHARATER_NOT_THERE
                            });
                        }
                        break;

                    case SearchMatchOperations.Cancel:
                        lock (user)
                        {
                            user.SelectedCharacer = 0;
                            user.InQueue          = false;
                            netMsg.conn.Send(NetworkConstants.START_SEARCH_MATCH, new SearchMatch()
                            {
                                op = SearchMatchOperations.Cancel
                            });
                        }
                        break;

                    case SearchMatchOperations.CHECK_START:
                        matchQueue.CheckStart();
                        break;
                    }
                }
                else
                {
                    netMsg.conn.Send(NetworkConstants.START_SEARCH_MATCH, new SearchMatch()
                    {
                        op = SearchMatchOperations.ERR_ACCOUNT_NOT_FOUND
                    });
                }
            }

            return(true);
        }
Esempio n. 5
0
        public bool Execute(JHSNetworkMessage netMsg)
        {
            if (DbManager == null)
            {
                DbManager = AccountManager.Instance;
            }

            BuySkin packet = netMsg.ReadMessage <BuySkin>();

            if (packet != null)
            {
                uint       connectionId = netMsg.conn.connectionId;
                AccountOBJ user         = DbManager.GetOnlineByConnectionId(connectionId);
                if (user != null)
                {
                    ConfiModel model = ConfigManager.GetModel((int)packet.ModelId);
                    if (model == null)
                    {
                        netMsg.conn.Send(NetworkConstants.BUYCHARACTER, new BuySkinResponse()
                        {
                            STATUS = ITEM_CONFIG_WRONG
                        });
                        return(true);
                    }
                    //Silver Buy
                    if (packet.BuyType == 0)
                    {
                        //TO DO CHECK IF CHARACTER ALREADY HAS THE MODEL
                        lock (user)
                        {
                            if (user.Silver < model.SilverPrice)
                            {
                                netMsg.conn.Send(NetworkConstants.BUYCHARACTER, new BuySkinResponse()
                                {
                                    STATUS = NOT_ENOUGH_SILVER
                                });
                                return(true);
                            }
                            Characters ccc = new Characters(user.Id, model.ModelId)
                            {
                                SkinColorId   = model.SkinColorId,
                                EyeColorId    = model.EyeColorId,
                                HairColorId   = model.HairColorId,
                                ShirtColorId  = model.ShirtColorId,
                                PantsColorId  = model.PantsColorId,
                                BootsColorId  = model.BootsColorId,
                                GlovesColorId = model.GlovesColorId
                            };
                            ccc.PlayerId = DbService.SaveEntity(ccc);
                            CharacterOBJ obj = new CharacterOBJ(ccc);
                            user.Skins.Add(obj.PlayerId, obj);
                            user.ResetNotification();
                            user.Silver -= model.SilverPrice;
                            DbService.SubmitUpdate2Queue(user);
                            netMsg.conn.Send(NetworkConstants.BUYCHARACTER, new BuySkinResponse()
                            {
                                STATUS = SUCCESS, Gold = (uint)user.Gold, Silver = (uint)user.Silver, character = obj.GetServerChar()
                            });
                            return(true);
                        }
                    }
                    else // GOLD BUY
                    {
                        //TO DO CHECK IF CHARACTER ALREADY HAS THE MODEL
                        lock (user)
                        {
                            if (user.Gold < model.GoldPrice)
                            {
                                netMsg.conn.Send(NetworkConstants.BUYCHARACTER, new BuySkinResponse()
                                {
                                    STATUS = NOT_ENOUGH_GOLD
                                });
                                return(true);
                            }
                            Characters ccc = new Characters(user.Id, model.ModelId)
                            {
                                SkinColorId   = model.SkinColorId,
                                EyeColorId    = model.EyeColorId,
                                HairColorId   = model.HairColorId,
                                ShirtColorId  = model.ShirtColorId,
                                PantsColorId  = model.PantsColorId,
                                BootsColorId  = model.BootsColorId,
                                GlovesColorId = model.GlovesColorId
                            };
                            ccc.PlayerId = DbService.SaveEntity(ccc);
                            CharacterOBJ obj = new CharacterOBJ(ccc);
                            user.Skins.Add(obj.PlayerId, obj);
                            user.Gold -= model.GoldPrice;
                            DbService.SubmitUpdate2Queue(user);
                            netMsg.conn.Send(NetworkConstants.BUYCHARACTER, new BuySkinResponse()
                            {
                                STATUS = SUCCESS, Gold = (uint)user.Gold, Silver = (uint)user.Silver, character = obj.GetServerChar()
                            });
                            return(true);
                        }
                    }
                }
            }

            return(true);
        }
Esempio n. 6
0
        public bool Execute(JHSNetworkMessage netMsg)
        {
            if (DbManager == null)
            {
                DbManager = AccountManager.Instance;
            }

            GWMainMenu packet = netMsg.ReadMessage <GWMainMenu>();

            if (packet != null)
            {
                uint       connectionId = netMsg.conn.connectionId;
                AccountOBJ user         = DbManager.GetOnlineByConnectionId(connectionId);
                if (user != null)
                {
                    int total = 0;
                    if (packet.SkinColorId_changed)
                    {
                        total += Settings.PRICE_PER_COLOR_CHANGE;
                    }
                    if (packet.HairColorId_changed)
                    {
                        total += Settings.PRICE_PER_COLOR_CHANGE;
                    }
                    if (packet.EyeColorId_changed)
                    {
                        total += Settings.PRICE_PER_COLOR_CHANGE;
                    }
                    if (packet.ShirtColorId_changed)
                    {
                        total += Settings.PRICE_PER_COLOR_CHANGE;
                    }
                    if (packet.PantsColorId_changed)
                    {
                        total += Settings.PRICE_PER_COLOR_CHANGE;
                    }
                    if (packet.BootsColorId_changed)
                    {
                        total += Settings.PRICE_PER_COLOR_CHANGE;
                    }
                    if (packet.GlovesColorId_changed)
                    {
                        total += Settings.PRICE_PER_COLOR_CHANGE;
                    }

                    if (total == 0)
                    {
                        return(true);
                    }

                    lock (user)
                    {
                        if (user.Silver < total)
                        {
                            netMsg.conn.Send(NetworkConstants.BUYCOLORCHANGE, new HeroBuyColorResponse()
                            {
                                STATUS = NOT_ENOUGH_SILVER
                            });
                            return(true);
                        }
                        CharacterOBJ player = user.GetPlayer(packet.PlayerId);

                        if (packet.SkinColorId_changed)
                        {
                            player.SkinColorId = packet.SkinColorId;
                        }
                        if (packet.HairColorId_changed)
                        {
                            player.HairColorId = packet.HairColorId;
                        }
                        if (packet.EyeColorId_changed)
                        {
                            player.EyeColorId = packet.EyeColorId;
                        }
                        if (packet.ShirtColorId_changed)
                        {
                            player.ShirtColorId = packet.ShirtColorId;
                        }
                        if (packet.PantsColorId_changed)
                        {
                            player.PantsColorId = packet.PantsColorId;
                        }
                        if (packet.BootsColorId_changed)
                        {
                            player.BootsColorId = packet.BootsColorId;
                        }
                        if (packet.GlovesColorId_changed)
                        {
                            player.GlovesColorId = packet.GlovesColorId;
                        }

                        DbService.SubmitUpdate2Queue(player);
                        user.Silver = user.Silver - total;
                        user.ResetNotification();
                        DbService.SubmitUpdate2Queue(user);
                        HeroBuyColorResponse response = new HeroBuyColorResponse()
                        {
                            STATUS                = 255,
                            PlayerId              = packet.PlayerId,
                            SkinColorId           = packet.SkinColorId,
                            SkinColorId_changed   = packet.SkinColorId_changed,
                            HairColorId           = packet.HairColorId,
                            HairColorId_changed   = packet.HairColorId_changed,
                            EyeColorId            = packet.EyeColorId,
                            EyeColorId_changed    = packet.EyeColorId_changed,
                            ShirtColorId          = packet.ShirtColorId,
                            ShirtColorId_changed  = packet.ShirtColorId_changed,
                            PantsColorId          = packet.PantsColorId,
                            PantsColorId_changed  = packet.PantsColorId_changed,
                            BootsColorId          = packet.BootsColorId,
                            BootsColorId_changed  = packet.BootsColorId_changed,
                            GlovesColorId         = packet.GlovesColorId,
                            GlovesColorId_changed = packet.GlovesColorId_changed,
                        };
                        response.STATUS = SUCCESS;
                        response.Silver = (uint)user.Silver;

                        netMsg.conn.Send(NetworkConstants.BUYCOLORCHANGE, response);
                        return(true);
                    }
                }
                else
                {
                    netMsg.conn.Send(NetworkConstants.BUYCOLORCHANGE, new HeroBuyColorResponse()
                    {
                        STATUS = USER_NOT_FOUND
                    });
                }
            }
            return(true);
        }