public static void Processar() { List <Dictionary <string, object> > contas = ControladorODBC.ODBCRecuperarListaUsuariosNaoAtivos(); if (contas.Count > 0) { Console.WriteLine("* Iniciando processo de Criacao de Contas."); } foreach (Dictionary <string, object> conta in contas) { int idUsuario = Convert.ToInt32(conta["IdUsuario"].ToString()); string login = conta["Login"].ToString(); string senha = conta["Senha"].ToString(); if (Accounts.GetAccount(login) == null) { Account novaConta = new Account(login, senha); Console.WriteLine("** Conta criada: {0} **", login); ControladorODBC.ODBCAtivarContaUsuario(idUsuario, login); } else { Console.WriteLine("** Erro: Conta {0} ja existe! **", login); } } }
private void SetModifiedValuesInListRaceSkillCap() { List <double> listaSkills = ControladorODBC.ODBCRecuperarSkillsCustomRace(this._name, this.FirstColumnSkillsInTable, this.LastColumnSkillsInTable); for (int i = 0; i < this._listRaceSkillCapValues.Count; i++) { this._listRaceSkillCapValues[i] = listaSkills[i]; } }
public virtual void Dispose(bool flush) { // Genova: Usuário desconectando do servidor... if (m_Mobile is Mobile) { ControladorODBC.ODBCDispose(m_Mobile); } if (m_Socket == null || m_Disposing) { return; } m_Disposing = true; if (flush) { flush = Flush(); } try { m_Socket.Shutdown(SocketShutdown.Both); } catch (SocketException ex) { TraceException(ex); } try { m_Socket.Close(); SocketPool.ReleaseSocket(m_Socket); } catch (SocketException ex) { TraceException(ex); } if (m_RecvBuffer != null) { m_ReceiveBufferPool.ReleaseBuffer(m_RecvBuffer); } m_Socket = null; m_Buffer = null; m_RecvBuffer = null; m_OnReceive = null; m_OnSend = null; m_Running = false; m_Disposed.Enqueue(this); if (/*!flush &&*/ !m_SendQueue.IsEmpty) { lock (m_SendQueue) m_SendQueue.Clear(); } }
public static void AplicarAlteracoesCriatura(BaseCreature criatura, string caminhoObjetoCriatura, string tituloCriatura, Map mapa, bool chanceParagon) { List <Dictionary <string, object> > registros = ControladorODBC.ODBCRecuperarInformacoesMobile(caminhoObjetoCriatura); if (registros.Count <= 0) { Console.WriteLine("** ODBCSpawner: NPC {0} nao encontrado! Adicionando na base de dados. **", caminhoObjetoCriatura); ControladorODBC.ODBCInserirInformacoesMobile(caminhoObjetoCriatura, tituloCriatura); } else { foreach (Dictionary <string, object> registro in registros) { int idTraducaoMobiles = Convert.ToInt32(registro["IdTraducaoMobiles"].ToString()); string classe = registro["Classe"].ToString(); string nome = registro["Nome"].ToString(); string nomeTraduzido = registro["NomeTraduzido"].ToString(); string titulo = registro["Titulo"].ToString(); string tituloTraduzido = registro["TituloTraduzido"].ToString(); int status = Convert.ToInt32(registro["Status"].ToString()); int paragon = Convert.ToInt32(registro["Paragon"].ToString()); if (status == 1) { Console.WriteLine("** ODBCSpawner: Aplicando alteracoes para {0}. **", nome); // Alterando nome if (nomeTraduzido.Length > 0) { criatura.Name = nomeTraduzido; } // Alterando titulo if (tituloTraduzido.Length > 0) { criatura.Title = tituloTraduzido; } // Calcular chance de ser Paragon if (mapa != null) { if (paragon == 1 && (mapa == Map.Ilshenar && chanceParagon)) { criatura.IsParagon = true; } } } else { Console.WriteLine("** ODBCSpawner: NPC {0} nao esta ativo. **", nome); } } } }
public static void Save(bool message) { if (m_Saving || AsyncWriter.ThreadCount > 0) { return; } NetState.FlushAll(); NetState.Pause(); m_Saving = true; if (message) { Broadcast(0x35, true, "The world is saving, please wait."); } SaveStrategy strategy = SaveStrategy.Acquire(); Console.WriteLine("Core: Using {0} save strategy", strategy.Name.ToLowerInvariant()); Console.Write("World: Saving..."); Stopwatch watch = Stopwatch.StartNew(); if (!Directory.Exists("Saves/Mobiles/")) { Directory.CreateDirectory("Saves/Mobiles/"); } if (!Directory.Exists("Saves/Items/")) { Directory.CreateDirectory("Saves/Items/"); } if (!Directory.Exists("Saves/Guilds/")) { Directory.CreateDirectory("Saves/Guilds/"); } /*using ( SaveMetrics metrics = new SaveMetrics() ) {*/ strategy.Save(null); /*}*/ try { EventSink.InvokeWorldSave(new WorldSaveEventArgs(message)); } catch (Exception e) { throw new Exception("World Save event threw an exception. Save failed!", e); } watch.Stop(); m_Saving = false; ProcessSafetyQueues(); strategy.ProcessDecay(); Console.WriteLine("done in {0:F2} seconds.", watch.Elapsed.TotalSeconds); // Genova: confirmar personagens não confirmados. ControladorODBC.ODBCConfirmarPersonagensNaoConfirmados(); if (message) { Broadcast(0x35, true, "World save complete. The entire process took {0:F1} seconds.", watch.Elapsed.TotalSeconds); } NetState.Resume(); }
public static void Load() { if (m_Loaded) { return; } m_Loaded = true; m_LoadingType = null; Console.Write("World: Loading..."); Stopwatch watch = Stopwatch.StartNew(); m_Loading = true; _addQueue = new Queue <IEntity>(); _deleteQueue = new Queue <IEntity>(); int mobileCount = 0, itemCount = 0, guildCount = 0; object[] ctorArgs = new object[1]; Type[] ctorTypes = new Type[1] { typeof(Serial) }; List <ItemEntry> items = new List <ItemEntry>(); List <MobileEntry> mobiles = new List <MobileEntry>(); List <GuildEntry> guilds = new List <GuildEntry>(); if (File.Exists(MobileIndexPath) && File.Exists(MobileTypesPath)) { using (FileStream idx = new FileStream(MobileIndexPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryReader idxReader = new BinaryReader(idx); using (FileStream tdb = new FileStream(MobileTypesPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryReader tdbReader = new BinaryReader(tdb); int count = tdbReader.ReadInt32(); ArrayList types = new ArrayList(count); for (int i = 0; i < count; ++i) { string typeName = tdbReader.ReadString(); Type t = ScriptCompiler.FindTypeByFullName(typeName); if (t == null) { Console.WriteLine("failed"); Console.WriteLine("Error: Type '{0}' was not found. Delete all of those types? (y/n)", typeName); if (Console.ReadKey(true).Key == ConsoleKey.Y) { types.Add(null); Console.Write("World: Loading..."); continue; } Console.WriteLine("Types will not be deleted. An exception will be thrown when you press return"); throw new Exception(String.Format("Bad type '{0}'", typeName)); } ConstructorInfo ctor = t.GetConstructor(ctorTypes); if (ctor != null) { types.Add(new object[] { ctor, null }); } else { throw new Exception(String.Format("Type '{0}' does not have a serialization constructor", t)); } } mobileCount = idxReader.ReadInt32(); m_Mobiles = new Dictionary <Serial, Mobile>(mobileCount); for (int i = 0; i < mobileCount; ++i) { int typeID = idxReader.ReadInt32(); int serial = idxReader.ReadInt32(); long pos = idxReader.ReadInt64(); int length = idxReader.ReadInt32(); object[] objs = ( object[] )types[typeID]; if (objs == null) { continue; } Mobile m = null; ConstructorInfo ctor = ( ConstructorInfo )objs[0]; string typeName = ( string )objs[1]; try { ctorArgs[0] = ( Serial )serial; m = ( Mobile )(ctor.Invoke(ctorArgs)); } catch { } if (m != null) { mobiles.Add(new MobileEntry(m, typeID, typeName, pos, length)); AddMobile(m); } } tdbReader.Close(); } idxReader.Close(); } } else { m_Mobiles = new Dictionary <Serial, Mobile>(); } if (File.Exists(ItemIndexPath) && File.Exists(ItemTypesPath)) { using (FileStream idx = new FileStream(ItemIndexPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryReader idxReader = new BinaryReader(idx); using (FileStream tdb = new FileStream(ItemTypesPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryReader tdbReader = new BinaryReader(tdb); int count = tdbReader.ReadInt32(); ArrayList types = new ArrayList(count); for (int i = 0; i < count; ++i) { string typeName = tdbReader.ReadString(); Type t = ScriptCompiler.FindTypeByFullName(typeName); if (t == null) { Console.WriteLine("failed"); Console.WriteLine("Error: Type '{0}' was not found. Delete all of those types? (y/n)", typeName); if (Console.ReadKey(true).Key == ConsoleKey.Y) { types.Add(null); Console.Write("World: Loading..."); continue; } Console.WriteLine("Types will not be deleted. An exception will be thrown when you press return"); throw new Exception(String.Format("Bad type '{0}'", typeName)); } ConstructorInfo ctor = t.GetConstructor(ctorTypes); if (ctor != null) { types.Add(new object[] { ctor, typeName }); } else { throw new Exception(String.Format("Type '{0}' does not have a serialization constructor", t)); } } itemCount = idxReader.ReadInt32(); m_Items = new Dictionary <Serial, Item>(itemCount); for (int i = 0; i < itemCount; ++i) { int typeID = idxReader.ReadInt32(); int serial = idxReader.ReadInt32(); long pos = idxReader.ReadInt64(); int length = idxReader.ReadInt32(); object[] objs = ( object[] )types[typeID]; if (objs == null) { continue; } Item item = null; ConstructorInfo ctor = ( ConstructorInfo )objs[0]; string typeName = ( string )objs[1]; try { ctorArgs[0] = ( Serial )serial; item = ( Item )(ctor.Invoke(ctorArgs)); } catch { } if (item != null) { items.Add(new ItemEntry(item, typeID, typeName, pos, length)); AddItem(item); } } tdbReader.Close(); } idxReader.Close(); } } else { m_Items = new Dictionary <Serial, Item>(); } if (File.Exists(GuildIndexPath)) { using (FileStream idx = new FileStream(GuildIndexPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryReader idxReader = new BinaryReader(idx); guildCount = idxReader.ReadInt32(); CreateGuildEventArgs createEventArgs = new CreateGuildEventArgs(-1); for (int i = 0; i < guildCount; ++i) { idxReader.ReadInt32(); //no typeid for guilds int id = idxReader.ReadInt32(); long pos = idxReader.ReadInt64(); int length = idxReader.ReadInt32(); createEventArgs.Id = id; BaseGuild guild = EventSink.InvokeCreateGuild(createEventArgs); if (guild != null) { guilds.Add(new GuildEntry(guild, pos, length)); } } idxReader.Close(); } } bool failedMobiles = false, failedItems = false, failedGuilds = false; Type failedType = null; Serial failedSerial = Serial.Zero; Exception failed = null; int failedTypeID = 0; if (File.Exists(MobileDataPath)) { using (FileStream bin = new FileStream(MobileDataPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin)); for (int i = 0; i < mobiles.Count; ++i) { MobileEntry entry = mobiles[i]; Mobile m = entry.Mobile; if (m != null) { reader.Seek(entry.Position, SeekOrigin.Begin); try { m_LoadingType = entry.TypeName; m.Deserialize(reader); if (reader.Position != (entry.Position + entry.Length)) { throw new Exception(String.Format("***** Bad serialize on {0} *****", m.GetType())); } } catch (Exception e) { mobiles.RemoveAt(i); failed = e; failedMobiles = true; failedType = m.GetType(); failedTypeID = entry.TypeID; failedSerial = m.Serial; break; } } } reader.Close(); } } if (!failedMobiles && File.Exists(ItemDataPath)) { using (FileStream bin = new FileStream(ItemDataPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin)); for (int i = 0; i < items.Count; ++i) { ItemEntry entry = items[i]; Item item = entry.Item; if (item != null) { reader.Seek(entry.Position, SeekOrigin.Begin); try { m_LoadingType = entry.TypeName; item.Deserialize(reader); if (reader.Position != (entry.Position + entry.Length)) { throw new Exception(String.Format("***** Bad serialize on {0} *****", item.GetType())); } } catch (Exception e) { items.RemoveAt(i); failed = e; failedItems = true; failedType = item.GetType(); failedTypeID = entry.TypeID; failedSerial = item.Serial; break; } } } reader.Close(); } } m_LoadingType = null; if (!failedMobiles && !failedItems && File.Exists(GuildDataPath)) { using (FileStream bin = new FileStream(GuildDataPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin)); for (int i = 0; i < guilds.Count; ++i) { GuildEntry entry = guilds[i]; BaseGuild g = entry.Guild; if (g != null) { reader.Seek(entry.Position, SeekOrigin.Begin); try { g.Deserialize(reader); if (reader.Position != (entry.Position + entry.Length)) { throw new Exception(String.Format("***** Bad serialize on Guild {0} *****", g.Id)); } } catch (Exception e) { guilds.RemoveAt(i); failed = e; failedGuilds = true; failedType = typeof(BaseGuild); failedTypeID = g.Id; failedSerial = g.Id; break; } } } reader.Close(); } } if (failedItems || failedMobiles || failedGuilds) { Console.WriteLine("An error was encountered while loading a saved object"); Console.WriteLine(" - Type: {0}", failedType); Console.WriteLine(" - Serial: {0}", failedSerial); Console.WriteLine("Delete the object? (y/n)"); if (Console.ReadKey(true).Key == ConsoleKey.Y) { if (failedType != typeof(BaseGuild)) { Console.WriteLine("Delete all objects of that type? (y/n)"); if (Console.ReadKey(true).Key == ConsoleKey.Y) { if (failedMobiles) { for (int i = 0; i < mobiles.Count;) { if (mobiles[i].TypeID == failedTypeID) { mobiles.RemoveAt(i); } else { ++i; } } } else if (failedItems) { for (int i = 0; i < items.Count;) { if (items[i].TypeID == failedTypeID) { items.RemoveAt(i); } else { ++i; } } } } } SaveIndex <MobileEntry>(mobiles, MobileIndexPath); SaveIndex <ItemEntry>(items, ItemIndexPath); SaveIndex <GuildEntry>(guilds, GuildIndexPath); } Console.WriteLine("After pressing return an exception will be thrown and the server will terminate"); Console.ReadLine(); throw new Exception(String.Format("Load failed (items={0}, mobiles={1}, guilds={2}, type={3}, serial={4})", failedItems, failedMobiles, failedGuilds, failedType, failedSerial), failed); } EventSink.InvokeWorldLoad(); m_Loading = false; ProcessSafetyQueues(); foreach (Item item in m_Items.Values) { if (item.Parent == null) { item.UpdateTotals(); } item.ClearProperties(); } foreach (Mobile m in m_Mobiles.Values) { m.UpdateRegion(); // Is this really needed? m.UpdateTotals(); m.ClearProperties(); } watch.Stop(); Console.WriteLine("done ({1} items, {2} mobiles) ({0:F2} seconds)", watch.Elapsed.TotalSeconds, m_Items.Count, m_Mobiles.Count); // Genova: remover personagens não confirmados. ControladorODBC.ODBCRemoverPersonagensNaoConfirmados(); }
public static void Processar() { ControladorODBC.ODBCProcessarMensagensGlobal(); }
public void DistribuirPontosDeExperiencia() { for (int contador = (this.DanosInfligidos.Count - 1); contador >= 0; --contador) { if (contador >= this.DanosInfligidos.Count) { continue; } DamageEntry danoInfligido = (DamageEntry)this.DanosInfligidos[contador]; if (danoInfligido.HasExpired) { continue; } Mobile atacante = danoInfligido.Damager; if (atacante == null || atacante.Deleted || !atacante.Player) { continue; } else if (atacante == null || atacante.Deleted) { continue; } if (atacante is BaseCreature) { BaseCreature criatura = (BaseCreature)atacante; if (criatura.Controlled && criatura.ControlMaster != null) { atacante = criatura.ControlMaster; } else if (criatura.Summoned && criatura.SummonMaster != null) { atacante = criatura.SummonMaster; } } else if (atacante is PlayerMobile) { if (this.AssassinadoPor is BaseGuard) { atacante.SendMessage("Os guardas fizeram o trabalho sujo! Você não recebe pontos de experiência."); } else if ((this.Domado && this.MestreDomador != null) || (this.MestreDomador == atacante) || (this.Invocado && this.MestreBruxo != null) || this.CriaturaRessureta) { if (this.Invocado && this.MestreBruxo != null) { atacante.SendMessage("Você matou um monstro invocado, e não recebe pontos de experiência."); } else if (this.MestreDomador == atacante || this.CriaturaRessureta) { atacante.SendMessage("Você matou um animal domado e não recebe pontos de experiência."); } } else { PlayerMobile jogadorAtacante = atacante as PlayerMobile; int pontosExperiencia = this.CalcularValorGanhoComExperiencia(jogadorAtacante.Fame); if (pontosExperiencia < 0) { pontosExperiencia = 0; } jogadorAtacante.SendMessage("Você recebeu {0} pontos de experiência", pontosExperiencia); ControladorODBC.ODBCConcederPontosXP(jogadorAtacante.Account.Username, jogadorAtacante.Name, pontosExperiencia); } } } }
public static void Processar(Mobile personagem, string nomePersonagem) { ControladorODBC.ODBCRegistrarPersonagem(personagem, nomePersonagem); }
public static void Processar() { string tempoOnline = AdminGump.FormatTimeSpan(DateTime.Now - Clock.ServerStart); ControladorODBC.ODBCProcessarStatusServidor(tempoOnline); }
private void ODBCGiveLoot() { List <Dictionary <string, object> > listaLoots = ControladorODBC.ODBCGiveLoot(this.NomeTipoCriatura, this.NomeCriatura); foreach (Dictionary <string, object> linha in listaLoots) { int id = Convert.ToInt32(linha["IdLoteGenerico"].ToString()); int quantidade = Convert.ToInt32(linha["Quantidade"].ToString()); int ouro = 0; string nome = linha["Classe"].ToString(); string item = linha["Item"].ToString(); if (item.ToUpper().Equals("OURO") || item.ToUpper().Equals("GOLD")) { ouro = Convert.ToInt32(quantidade); } else if (item == "1cscroll" && quantidade > 0) { this.PackItem(Loot.RandomScroll(0, 7, SpellbookType.Regular)); } else if (item == "2cscroll" && quantidade > 0) { this.PackItem(Loot.RandomScroll(8, 15, SpellbookType.Regular)); } else if (item == "3cscroll" && quantidade > 0) { this.PackItem(Loot.RandomScroll(16, 23, SpellbookType.Regular)); } else if (item == "4cscroll" && quantidade > 0) { this.PackItem(Loot.RandomScroll(24, 31, SpellbookType.Regular)); } else if (item == "5cscroll" && quantidade > 0) { this.PackItem(Loot.RandomScroll(32, 39, SpellbookType.Regular)); } else if (item == "6cscroll" && quantidade > 0) { this.PackItem(Loot.RandomScroll(40, 47, SpellbookType.Regular)); } else if (item == "7cscroll" && quantidade > 0) { this.PackItem(Loot.RandomScroll(48, 55, SpellbookType.Regular)); } else if (item == "8cscroll" && quantidade > 0) { this.PackItem(Loot.RandomScroll(56, 63, SpellbookType.Regular)); } else if (item == "necrolowscroll" && quantidade > 0) { this.PackItem(Loot.RandomScroll(0, 5, SpellbookType.Necromancer)); } else if (item == "necromedscroll" && quantidade > 0) { this.PackItem(Loot.RandomScroll(6, 10, SpellbookType.Necromancer)); } else if (item == "necrohighscroll" && quantidade > 0) { this.PackItem(Loot.RandomScroll(11, 15, SpellbookType.Necromancer)); } AddItemLoot.AddItem(this.BolsaCriatura, item, quantidade, ouro); } }
public static void EventSink_AccountLogin(AccountLoginEventArgs e) { if (!IPLimiter.SocketBlock && !IPLimiter.Verify(e.State.Address)) { e.Accepted = false; e.RejectReason = ALRReason.InUse; Console.WriteLine("Login: {0}: Past IP limit threshold", e.State); using (StreamWriter op = new StreamWriter("ipLimits.log", true)) op.WriteLine("{0}\tPast IP limit threshold\t{1}", e.State, DateTime.Now); return; } string un = e.Username; string pw = e.Password; e.Accepted = false; Account acct = Accounts.GetAccount(un) as Account; if (acct == null) { if (AutoAccountCreation && un.Trim().Length > 0) //To prevent someone from making an account of just '' or a bunch of meaningless spaces { e.State.Account = acct = CreateAccount(e.State, un, pw); e.Accepted = acct == null ? false : acct.CheckAccess(e.State); if (!e.Accepted) { e.RejectReason = ALRReason.BadComm; } } else { Console.WriteLine("Login: {0}: Invalid username '{1}'", e.State, un); e.RejectReason = ALRReason.Invalid; } } else if (!acct.HasAccess(e.State)) { Console.WriteLine("Login: {0}: Access denied for '{1}'", e.State, un); e.RejectReason = (m_LockdownLevel > AccessLevel.Player ? ALRReason.BadComm : ALRReason.BadPass); } else if (!acct.CheckPassword(pw)) { Console.WriteLine("Login: {0}: Invalid password for '{1}'", e.State, un); e.RejectReason = ALRReason.BadPass; } else if (acct.Banned) { Console.WriteLine("Login: {0}: Banned account '{1}'", e.State, un); e.RejectReason = ALRReason.Blocked; } else { Console.WriteLine("Login: {0}: Valid credentials for '{1}'", e.State, un); e.State.Account = acct; e.Accepted = true; acct.LogAccess(e.State); // Genova: Usuário conectando no servidor... ControladorODBC.ODBCReceive(e.State, un); } if (!e.Accepted) { AccountAttackLimiter.RegisterInvalidAccess(e.State); } }