public void OnDeleteChar(Packets.Client.DeleteChar p) { if (this.state != SESSION_STATE.CSERVER_SELECTED) { return; } int delIndex = (int)p.GetCharIndex(); if (this.Chars[delIndex] == null) { Console.WriteLine(this.User.Name + " sent invalid char index " + delIndex); Packets.Server.SendError p1 = new SagaLogin.Packets.Server.SendError(); p1.SetError(Packets.Server.ERROR_TYPE.ERROR1); this.netIO.SendPacket(p1, this.SessionID); return; } if (!this.User.chars.ContainsKey(this.activeWorldID)) { this.Disconnect(); return; } this.User.chars[this.activeWorldID].Remove(this.Chars[delIndex].charID); try { LoginServer.userDB.WriteUser(this.User); } catch (Exception) { this.Disconnect(); return; } try { LoginServer.charServerList[this.activeWorldID].charDB.DeleteChar(this.Chars[delIndex]); } catch (Exception) { this.Disconnect(); return; } this.Chars.RemoveAt(delIndex); Packets.Server.SendError p2 = new SagaLogin.Packets.Server.SendError(); p2.SetError(Packets.Server.ERROR_TYPE.NO_ERROR); this.netIO.SendPacket(p2, this.SessionID); }
public void OnCreateChar(Packets.Client.CreateChar p) { if (this.state != SESSION_STATE.CSERVER_SELECTED) { return; } bool charAlreadyExists = false; try { charAlreadyExists = LoginServer.charServerList[this.activeWorldID].charDB.CharExists(this.activeWorldID, p.GetCharName()); } catch (Exception) { this.Disconnect(); return; } if (charAlreadyExists) { Packets.Server.SendError p1 = new SagaLogin.Packets.Server.SendError(); p1.SetError(Packets.Server.ERROR_TYPE.ERROR1); this.netIO.SendPacket(p1, this.SessionID); return; } // WARNING: the data from the client needs to be validated! // this is INSECURE! ActorPC tempChar = new ActorPC(this.activeWorldID, p.GetCharName()); tempChar.userName = this.User.Name; tempChar.face = new byte[5]; tempChar.slots = new byte[7]; tempChar.details = new byte[6]; tempChar.face[0] = p.GetEye(); tempChar.face[1] = p.GetEyeColor(); tempChar.face[2] = p.GetEyebrows(); tempChar.face[3] = p.GetHair(); tempChar.face[4] = p.GetHairColor(); tempChar.weaponType = p.GetWeaponNameType(); tempChar.weaponName = p.GetWeaponName(); tempChar.race = RaceType.NORMAN; tempChar.jExp = 0; tempChar.cExp = 0; tempChar.cLevel = 1; tempChar.jLevel = 1; tempChar.job = JobType.NOVICE; tempChar.pendingDeletion = 0; tempChar.HP = Config.Instance.HP; tempChar.maxHP = Config.Instance.HP; tempChar.SP = Config.Instance.SP; tempChar.maxSP = Config.Instance.SP; tempChar.LC = 45; tempChar.maxLC = 45; tempChar.LP = 0; tempChar.maxLP = 5; tempChar.worldID = this.activeWorldID; tempChar.GMLevel = 1; tempChar.mapID = Config.Instance.Map; tempChar.x = Config.Instance.X; tempChar.y = Config.Instance.Y; tempChar.z = Config.Instance.Z; tempChar.yaw = 0; tempChar.str = Config.Instance.STR; tempChar.dex = Config.Instance.DEX; tempChar.intel = Config.Instance.INT; tempChar.con = Config.Instance.CON; tempChar.luk = 0; tempChar.stpoints = 0; tempChar.state = 0; tempChar.slots[0] = 0x00; // weapon set slot 0 tempChar.slots[1] = 0x00; // weapon set slot 1 tempChar.slots[2] = 0x00; // current set slot tempChar.slots[3] = 0x32; // invent slot? tempChar.slots[4] = 0x32; // ?? tempChar.slots[5] = 0x01; // weapon slot? tempChar.slots[6] = 0x00; // ?? tempChar.details[0] = 0x01; // pattern tempChar.details[1] = 0x01; // ear type tempChar.details[2] = 0x0C; // horn type tempChar.details[3] = 0x01; // horn color (not used) tempChar.details[4] = 0x01; // wing type tempChar.details[5] = 0x01; // wing color (not used) tempChar.sex = this.User.Sex; tempChar.sightRange = Global.MakeSightRange(6000); tempChar.maxMoveRange = 10000; // just a "guessed" number, we should find a better, smaller value which works tempChar.invisble = false; // this actor is visible to other actors tempChar.state = 0; tempChar.stance = 0; tempChar.inv = new SagaDB.Items.Inventory(50); // 50 item slots in the inventory // add 2 test items foreach (uint i in Config.Instance.Items) { tempChar.inv.AddItem(new Item((int)i)); } tempChar.BattleSkills = new Dictionary <uint, SkillInfo>(); foreach (uint i in Config.Instance.Skills) { tempChar.BattleSkills.Add(i, new SkillInfo()); } if (this.User.AccountID == -1) { this.User.AccountID = LoginServer.userDB.GetAccountID(this.User.Name); } try { LoginServer.charServerList[this.activeWorldID].charDB.CreateChar(ref tempChar, this.User.AccountID); } catch (Exception ex) { Logger.ShowError(ex, null); this.Disconnect(); return; } if (this.Chars == null) { this.Chars = new List <ActorPC>(); } this.Chars.Add(tempChar); if (!this.User.chars.ContainsKey(this.activeWorldID)) { this.User.chars[this.activeWorldID] = new List <uint>(); } this.User.chars[this.activeWorldID].Add(tempChar.charID); try { LoginServer.userDB.WriteUser(this.User); } catch (Exception) { this.Disconnect(); return; } Packets.Server.SendError p2 = new SagaLogin.Packets.Server.SendError(); p2.SetError(Packets.Server.ERROR_TYPE.NO_ERROR); this.netIO.SendPacket(p2, this.SessionID); }