Example #1
0
        public void OnPlayerLoad(Packet packet)
        {
            var characterId = packet.ReadInt();

            ThreadContext.Properties["CharacterID"] = characterId;

            if (RedisBackend.Instance.HoldoffPlayerConnection(characterId))
            {
                Program.MainForm.LogAppend("Bouncing charid: " + characterId);
                SendConnectToServer(Server.Instance.PublicIP.GetAddressBytes(), Server.Instance.Port, true);
                return;
            }


            if (RedisBackend.Instance.PlayerIsMigrating(characterId, true) == false)
            {
                var msg = "Disconnecting because not migrating. Charid: " + characterId;
                Server.Instance.ServerTraceDiscordReporter.Enqueue(msg);
                Program.MainForm.LogAppend(msg);
                goto cleanup_and_disconnect;
            }


            var uId = Server.Instance.CharacterDatabase.UserIDByCharID(characterId);

            ThreadContext.Properties["UserID"] = uId;
            if (Server.Instance.CharacterDatabase.IsBanned(uId))
            {
                var msg = "Disconnecting because banned. Charid: " + characterId + ". Userid: " + uId;
                Server.Instance.ServerTraceDiscordReporter.Enqueue(msg);
                Program.MainForm.LogAppend(msg);
                goto cleanup_and_disconnect;
            }

            if (Server.Instance.CharacterDatabase.IsIpBanned(IP))
            {
                var msg = "Disconnecting because IP banned. Charid: " + characterId + ". Userid: " + uId + ". IP: " + IP;
                Server.Instance.ServerTraceDiscordReporter.Enqueue(msg);
                Program.MainForm.LogAppend(msg);
                goto cleanup_and_disconnect;
            }

            if (Server.Instance.CharacterList.ContainsKey(characterId))
            {
                var msg = "Disconnecting characterId " + characterId + " from IP " + IP + ". Already connected in this channel.";
                Server.Instance.ServerTraceDiscordReporter.Enqueue(msg);
                Program.MainForm.LogAppend(msg);
                goto cleanup_and_disconnect;
            }

            var character  = new Character(characterId);
            var loadResult = character.Load(IP);

            if (loadResult != Character.LoadFailReasons.None)
            {
                var msg = "Disconnected characterId " + characterId + " from IP " + IP + ". " + loadResult;
                Server.Instance.ServerTraceDiscordReporter.Enqueue(msg);
                Program.MainForm.LogAppend(msg);
                goto cleanup_and_disconnect;
            }

            Player.Character = character;
            character.Player = Player;

            StartLogging();

            Program.MainForm.LogAppend(character.Name + " connected from IP " + IP + ".");

            Program.MainForm.ChangeLoad(true);
            Server.Instance.CharacterList.Add(characterId, character);
            if (character.IsGM)
            {
                Server.Instance.StaffCharacters.Add(character);
            }
            Loaded = true;

            //have to load summons after he joins the map, so i have moved this from the load method -Exile
            if (Server.Instance.CCIngPlayerList.TryGetValue(character.ID, out var info))
            {
                Server.Instance.CCIngPlayerList.Remove(character.ID);
            }

            var ccPacket = info?.Item1;

            if (ccPacket != null)
            {
                character.PrimaryStats.DecodeForCC(ccPacket);
            }

            character.PrimaryStats.CheckHPMP();

            MapPacket.SendJoinGame(character);

            if (character.IsGM)
            {
                string glevel = character.GMLevel == 1 ? "(GM Intern)" : character.GMLevel == 2 ? "(GM)" : "(Admin)";
                MessagePacket.SendNotice("Your GM Level: " + character.GMLevel + " " + glevel + ". Undercover? " + (character.Undercover ? "Yes" : "No"), character);
            }

            if (character.IsGM && !character.Undercover)
            {
                character.TryActivateHide();
            }

            character.Field.AddPlayer(character);

            if (ccPacket != null)
            {
                character.Summons.DecodeForCC(ccPacket);
            }

            MessagePacket.SendText(MessagePacket.MessageTypes.Header, Server.Instance.ScrollingHeader, character, MessagePacket.MessageMode.ToPlayer);

            Server.Instance.CenterConnection.RegisterCharacter(character.ID, character.Name, character.PrimaryStats.Job, character.PrimaryStats.Level, character.GMLevel);

            Server.Instance.CenterConnection.RequestBuddyListLoad(character.Name, false, character.PrimaryStats.BuddyListCapacity); //Sends a packet that request the buddylistload from the centerserver
            character.IsOnline = true;
            Server.Instance.CenterConnection.PlayerUpdateMap(character);

            // Just to be sure, check if he was banned

            if (RedisBackend.Instance.TryGetNonGameHackDetect(Player.Character.UserID, out var hax))
            {
                HackDetected = hax;
                OnHackDetected();
            }
            else if (HackDetected.HasValue)
            {
                OnHackDetected();
            }

            return;


cleanup_and_disconnect:

            Server.Instance.CCIngPlayerList.Remove(characterId);
            Disconnect();
        }
Example #2
0
        public void OnVarset(Character Sent, string Var, object Value, object Value2 = null, object Value3 = null)
        {
            if (this != Sent && Sent.IsGM && !Sent.IsAdmin) //Todo Admin levels
            {
                MessagePacket.SendNotice("You don't have the premission to edit other players stats!", Sent);
                //$"{Sent.Name} tried to edit another players stats without premission"
            }
            else
            {
                try
                {
                    MapPacket.AvatarModFlag        AvatarMod = 0;
                    CharacterStatsPacket.StatFlags dwFlag    = 0;

                    switch (Var.ToLower())
                    {
                    case "hp":
                        dwFlag         |= CharacterStatsPacket.StatFlags.Hp;
                        PrimaryStats.HP = Convert.ToInt16(Value);
                        break;

                    case "mp":
                        dwFlag         |= CharacterStatsPacket.StatFlags.Mp;
                        PrimaryStats.MP = Convert.ToInt16(Value);
                        break;

                    case "exp":
                        dwFlag          |= CharacterStatsPacket.StatFlags.Exp;
                        PrimaryStats.EXP = Convert.ToInt32(Value);
                        break;

                    case "maxhp":
                        dwFlag |= CharacterStatsPacket.StatFlags.MaxHp;
                        if (Value.ToString() == "0")
                        {
                            Value = "1";
                        }
                        PrimaryStats.MaxHP = Convert.ToInt16(Value);
                        break;

                    case "maxmp":
                        dwFlag |= CharacterStatsPacket.StatFlags.MaxMp;
                        if (Value.ToString() == "0")
                        {
                            Value = "1";
                        }
                        PrimaryStats.MaxMP = Convert.ToInt16(Value);
                        break;

                    case "ap":
                        dwFlag         |= CharacterStatsPacket.StatFlags.Ap;
                        PrimaryStats.AP = Convert.ToInt16(Value);
                        break;

                    case "sp":
                        dwFlag         |= CharacterStatsPacket.StatFlags.Sp;
                        PrimaryStats.SP = Convert.ToInt16(Value);
                        break;

                    case "str":
                        dwFlag          |= CharacterStatsPacket.StatFlags.Str;
                        PrimaryStats.Str = Convert.ToInt16(Value);
                        break;

                    case "dex":
                        dwFlag          |= CharacterStatsPacket.StatFlags.Dex;
                        PrimaryStats.Dex = Convert.ToInt16(Value);
                        break;

                    case "int":
                        dwFlag          |= CharacterStatsPacket.StatFlags.Int;
                        PrimaryStats.Int = Convert.ToInt16(Value);
                        break;

                    case "luk":
                        dwFlag          |= CharacterStatsPacket.StatFlags.Luk;
                        PrimaryStats.Luk = Convert.ToInt16(Value);
                        break;

                    case "fame":
                    case "pop":
                        dwFlag           |= CharacterStatsPacket.StatFlags.Fame;
                        PrimaryStats.Fame = Convert.ToInt16(Value);
                        break;

                    case "mesos":
                        dwFlag         |= CharacterStatsPacket.StatFlags.Mesos;
                        Inventory.Mesos = Convert.ToInt32(Value);
                        break;

                    case "job":
                    {
                        var Job = Convert.ToInt16(Value);
                        if (DataProvider.HasJob(Job) || Job == 0)
                        {
                            dwFlag          |= CharacterStatsPacket.StatFlags.Job;
                            PrimaryStats.Job = Job;
                        }
                        else
                        {
                            MessagePacket.SendNotice($"Job {Job} does not exist.", Sent);
                        }
                        break;
                    }

                    case "skill":
                    {
                        var SkillID = Convert.ToInt32(Value);
                        if (DataProvider.Skills.TryGetValue(SkillID, out var Skill))
                        {
                            if (Value2 == null)
                            {
                                Value2 = Skill.MaxLevel;
                            }
                            Skills.SetSkillPoint(SkillID, Convert.ToByte(Value2), true);
                        }
                        else
                        {
                            MessagePacket.SendNotice($"Skill {SkillID} does not exist.", Sent);
                        }
                        break;
                    }

                    case "level":
                        dwFlag |= CharacterStatsPacket.StatFlags.Level;
                        Level   = Convert.ToByte(Value);
                        MapPacket.SendPlayerLevelupAnim(this);
                        break;

                    case "skin":
                    {
                        var SkinID = Convert.ToByte(Value);
                        if (SkinID >= 0 && SkinID < 6)
                        {
                            AvatarMod |= MapPacket.AvatarModFlag.Skin;
                            dwFlag    |= CharacterStatsPacket.StatFlags.Skin;
                            Skin       = SkinID;
                        }
                        else
                        {
                            MessagePacket.SendNotice($"Skin {SkinID} does not exist.", Sent);
                        }
                        break;
                    }

                    case "face":
                    {
                        var FaceID = Convert.ToInt32(Value);
                        if (DataProvider.Equips.ContainsKey(FaceID))
                        {
                            AvatarMod |= MapPacket.AvatarModFlag.Face;
                            dwFlag    |= CharacterStatsPacket.StatFlags.Eyes;
                            Face       = FaceID;
                        }
                        else
                        {
                            MessagePacket.SendNotice($"Face {FaceID} does not exist.", Sent);
                        }
                        break;
                    }

                    case "hair":
                    {
                        var HairID = Convert.ToInt32(Value);
                        if (DataProvider.Equips.ContainsKey(HairID))
                        {
                            AvatarMod |= MapPacket.AvatarModFlag.Equips;
                            dwFlag    |= CharacterStatsPacket.StatFlags.Hair;
                            Hair       = HairID;
                        }
                        else
                        {
                            MessagePacket.SendNotice($"Hair {HairID} does not exist.", Sent);
                        }
                        break;
                    }

                    case "gender":
                    {
                        Gender = ParseGenderString(Value.ToString());
                        Server.Instance.CharacterDatabase.RunQuery(
                            "UPDATE characters SET gender = @gender WHERE id = @id",
                            "@gender", Gender,
                            "@id", ID
                            );

                        MessagePacket.SendNotice($"Gender set to {(Gender == 0 ? "male" : (Gender == 2 ? "Unisex" : "female"))}. Please relog.", this);
                        break;
                    }

                    case "accgender":
                    {
                        var gender = ParseGenderString(Value.ToString());
                        Server.Instance.CharacterDatabase.RunQuery(
                            "UPDATE users SET gender = @gender WHERE ID = @id",
                            "@gender", gender,
                            "@id", UserID
                            );

                        MessagePacket.SendNotice($"Account gender set to {(gender == 0 ? "male" : (gender == 2 ? "Unisex" : "female"))}", this);
                        break;
                    }

                    case "map":
                    case "field":
                    {
                        var FieldID = Convert.ToInt32(Value);
                        if (DataProvider.Maps.ContainsKey(FieldID))
                        {
                            ChangeMap(FieldID);
                        }
                        else
                        {
                            MessagePacket.SendText(MessagePacket.MessageTypes.RedText, "Map not found.", this, MessagePacket.MessageMode.ToPlayer);
                        }
                        break;
                    }

                    default:
                        MessagePacket.SendNotice($"{Var} is not a valid Variable!", Sent);
                        return;
                    }

                    if (dwFlag != 0)
                    {
                        CharacterStatsPacket.SendUpdateStat(this, true, dwFlag);
                    }

                    if (AvatarMod != 0)
                    {
                        MapPacket.SendAvatarModified(this, AvatarMod);
                    }
                }
                catch (Exception ex)
                {
                    MessagePacket.SendNotice(ex.Message, Sent);
                }
            }
        }