private void ProcessCreatePacket(CreatePacket pkt) { // try // { var nextCharId = 1; nextCharId = db.GetNextCharId(account); var cmd = db.CreateQuery(); cmd.CommandText = "SELECT maxCharSlot FROM accounts WHERE id=@accId;"; cmd.Parameters.AddWithValue("@accId", account.AccountId); var maxChar = (int)cmd.ExecuteScalar(); cmd = db.CreateQuery(); cmd.CommandText = "SELECT COUNT(id) FROM characters WHERE accId=@accId AND dead = FALSE;"; cmd.Parameters.AddWithValue("@accId", account.AccountId); var currChar = (int)(long)cmd.ExecuteScalar(); if (currChar >= maxChar) { Disconnect(); return; } if (CheckAccountInUse(account.AccountId) != false) { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine(@"Account in use: " + account.AccountId); Console.ForegroundColor = ConsoleColor.White; SendPacket(new FailurePacket { Message = "Account in use! Retrying..." }); return; } character = Database.CreateCharacter(pkt.ObjectType, nextCharId); var stats = new int[] { character.MaxHitPoints, character.MaxMagicPoints, character.Attack, character.Defense, character.Speed, character.Dexterity, character.HpRegen, character.MpRegen, }; var ok = true; cmd = db.CreateQuery(); cmd.Parameters.AddWithValue("@accId", account.AccountId); cmd.Parameters.AddWithValue("@charId", nextCharId); cmd.Parameters.AddWithValue("@charType", pkt.ObjectType); cmd.Parameters.AddWithValue("@items", Utils.GetCommaSepString(character.EquipSlots())); cmd.Parameters.AddWithValue("@stats", Utils.GetCommaSepString(stats)); cmd.Parameters.AddWithValue("@fameStats", character.FameStats.ToString()); cmd.CommandText = "INSERT INTO characters (accId, charId, charType, level, exp, fame, items, hp, mp, stats, dead, pet, fameStats) VALUES (@accId, @charId, @charType, 1, 0, 0, @items, 100, 100, @stats, FALSE, -1, @fameStats);"; var v = cmd.ExecuteNonQuery(); ok = v > 0; if (ok) { if (account.Bonuses != null) { if (account.Bonuses.Count > 0) { var chrEquip = character.Equipment; for (var i = 4; i < 12; i++) { if (chrEquip[i] == -1) { chrEquip[i] = account.Bonuses.First(); account.Bonuses.Remove(account.Bonuses.First()); SendPacket(new TextPacket { Name = "", BubbleTime = 0, Stars = -1, Text = "You received " + XmlDatas.TypeToId[chrEquip[i]] + "." }); if (account.Bonuses.Count == 0) { break; } } } db.SetBonuses(account.AccountId, account.Bonuses); character.Equipment = chrEquip; } else { } } else { account.Bonuses = new List <short>(); } if (IP.Gifts != null) { if (IP.Gifts.Count > 0) { var chrEquip = character.Equipment; for (var i = 4; i < 12; i++) { if (chrEquip[i] == -1) { chrEquip[i] = IP.Gifts.First(); IP.Gifts.Remove(IP.Gifts.First()); SendPacket(new TextPacket { Name = "", BubbleTime = 0, Stars = -1, Text = "You received " + XmlDatas.TypeToId[chrEquip[i]] + "." }); if (IP.Gifts.Count == 0) { break; } } } db.SetBonuses(IP.Address, IP.Gifts); character.Equipment = chrEquip; } else { } } else { IP.Gifts = new List <short>(); } db.SaveBackpacks(character, account); } if (ok) { var target = RealmManager.Worlds[targetWorld]; //Delay to let client load remote texture // target.Timers.Add(new WorldTimer(2000, (w, t) => SendPacket(new CreateResultPacket target.Timers.Add(new WorldTimer(500, (w, t) => SendPacket(new CreateResultPacket { CharacterID = character.CharacterId, ObjectID = RealmManager.Worlds[targetWorld].EnterWorld(entity = new Player(this)) }))); stage = ProtocalStage.Ready; } else { SendPacket(new FailurePacket { Message = "Failed to Load character." }); } // } // catch (Exception e) { } }
public void SaveCharacter(Account acc, Char chr) { Console.WriteLine("Saving " + acc.Name + "..."); MySqlCommand cmd = CreateQuery(); cmd.CommandText = @"UPDATE characters SET level=@level, exp=@exp, fame=@fame, items=@items, stats=@stats, hp=@hp, mp=@mp, tex1=@tex1, tex2=@tex2, pet=@pet, fameStats=@fameStats WHERE accId=@accId AND charId=@charId;"; cmd.Parameters.AddWithValue("@accId", acc.AccountId); cmd.Parameters.AddWithValue("@charId", chr.CharacterId); cmd.Parameters.AddWithValue("@level", chr.Level); cmd.Parameters.AddWithValue("@exp", chr.Exp); cmd.Parameters.AddWithValue("@fame", chr.CurrentFame); cmd.Parameters.AddWithValue("@items", Utils.GetCommaSepString(chr.EquipSlots())); cmd.Parameters.AddWithValue("@stats", Utils.GetCommaSepString(new[] { chr.MaxHitPoints, chr.MaxMagicPoints, chr.Attack, chr.Defense, chr.Speed, chr.HpRegen, chr.MpRegen, chr.Dexterity })); cmd.Parameters.AddWithValue("@hp", chr.HitPoints); cmd.Parameters.AddWithValue("@mp", chr.MagicPoints); cmd.Parameters.AddWithValue("@tex1", chr.Tex1); cmd.Parameters.AddWithValue("@tex2", chr.Tex2); cmd.Parameters.AddWithValue("@pet", chr.Pet); chr.PCStats = Convert.ToBase64String(ZlibStream.CompressBuffer(chr.FameStats.Write())) .Replace('+', '-') .Replace('/', '_'); cmd.Parameters.AddWithValue("@fameStats", chr.PCStats); cmd.ExecuteNonQuery(); cmd = CreateQuery(); cmd.CommandText = @"INSERT INTO classstats(accId, objType, bestLv, bestFame) VALUES(@accId, @objType, @bestLv, @bestFame) ON DUPLICATE KEY UPDATE bestLv = GREATEST(bestLv, @bestLv), bestFame = GREATEST(bestFame, @bestFame);"; cmd.Parameters.AddWithValue("@accId", acc.AccountId); cmd.Parameters.AddWithValue("@objType", chr.ObjectType); cmd.Parameters.AddWithValue("@bestLv", chr.Level); cmd.Parameters.AddWithValue("@bestFame", chr.CurrentFame); cmd.ExecuteNonQuery(); cmd.Dispose(); SaveBackpacks(chr, acc); }