public override void OnClientLoopStop() { IEnumerator e = new ArrayList(m_worldServers).GetEnumerator(); while (e.MoveNext()) { WorldConnection connection = (WorldConnection)e.Current; if (!connection.processWorldServerData()) { if (m_shutdown == false) { Console.WriteLine("Lost connection to world server " + connection.ToString()); LoginServer.Shutdown(); } else { m_worldServers.Remove(connection); } } } if (m_shutdown && m_worldServers.Count == 0) { base.Stop(); } Thread.Sleep(5); }
static void OnChangeMap(WorldConnection connection, WORLDMSG msgID, BinReader data) { uint id = data.ReadUInt32(); LoginClient client = LoginServer.GetLoginClientByCharacterID(id); client.IsChangingMap = true; }
static void OnRegisterVendor(WorldConnection connection, WORLDMSG msgID, BinReader data) { ulong vGUID = data.ReadUInt64(); uint id = data.ReadUInt32(); uint level = data.ReadUInt32(); string name = data.ReadString(); DBVendor vendor; if (id == 0) { Console.WriteLine("SpawnID was 0 for vendor registration"); } DataObject[] objs = DataServer.Database.SelectObjects(typeof(DBVendor), "SpawnID = '" + id + "'"); if (objs.Length == 0) { vendor = new DBVendor(); vendor.SpawnID = id; vendor.GUID = vGUID; vendor.Name = name; vendor.Level = level; DataServer.Database.AddNewObject(vendor); Console.WriteLine("Vendor " + vendor.ObjectId + " created"); } else { vendor = (DBVendor)objs[0]; vendor.GUID = vGUID; vendor.Level = level; Console.WriteLine("Vendor " + vendor.ObjectId + " registered"); DataServer.Database.SaveObject(vendor); } return; }
public static void HandlePacket(WorldConnection connection, WORLDMSG msgID, BinReader data) { try { DebugLogger.Logger.Log("LoginClient handling packet " + msgID.ToString()); bool handled_packet = false; ILoginServerPacketHandler handler = (ILoginServerPacketHandler)loginServerHandlers[msgID]; if (handler != null) { handled_packet = true; handler.HandlePacket(connection, msgID, data); } LoginServerPacketDelegate wspd = (LoginServerPacketDelegate)loginServerDelegates[(int)msgID]; if (wspd != null) { handled_packet = true; wspd(connection, msgID, data); } if (handled_packet == false) { DebugLogger.Logger.Log("WARNING: No valid handler found for " + msgID.ToString()); } } catch (Exception exp) { DebugLogger.Logger.Log("", exp); } }
static void OnAcquireGuids(WorldConnection connection, WORLDMSG msgID, BinReader data) { WorldPacket pkg = new WorldPacket(WORLDMSG.ACQUIRE_GUIDS_REPLY); pkg.Write(current_guid); current_guid += 200000; pkg.Write(current_guid++); connection.Send(pkg); }
static void InitGuids(WorldConnection connection) { WorldPacket pkg = new WorldPacket(WORLDMSG.INIT_GUIDS); pkg.Write(current_guid); current_guid += 200000; pkg.Write(current_guid); pkg.Write(++current_guid); current_guid += 200000; pkg.Write(current_guid++); connection.Send(pkg); }
public static void HandlePacket(WorldConnection connection, WORLDMSG msgID, BinReader data) { ILoginServerPacketHandler handler = (ILoginServerPacketHandler)loginServerHandlers[msgID]; if (handler != null) { handler.HandlePacket(connection, msgID, data); } LoginServerPacketDelegate wspd = (LoginServerPacketDelegate)loginServerDelegates[(int)msgID]; if (wspd != null) { wspd(connection, msgID, data); } }
public override void OnClientLoopStop() { try { IEnumerator e = new ArrayList(m_worldServers).GetEnumerator(); while (e.MoveNext()) { WorldConnection connection = (WorldConnection)e.Current; if (!connection.processWorldServerData()) { if (m_shutdown == false) { Console.WriteLine("Lost connection to world server " + connection.ToString()); LoginServer.Shutdown(); } else { m_worldServers.Remove(connection); } DebugLogger.Log("Lost connection to world server " + connection.ToString() + " -- Server will be restarted!"); LoginServer.RestartServer = true; } } if (m_shutdown && m_worldServers.Count == 0) { base.Stop(); } Thread.Sleep(5); } catch (Exception exp) { if (exp.GetType() != typeof(ThreadAbortException)) { DebugLogger.Log("Will restart server!", exp); } LoginServer.RestartServer = true; } }
static void OnDeleteDBObject(WorldConnection connection, WORLDMSG msgID, BinReader data) { try { string str = data.ReadString(); Type type = dbTypes.GetType(str, true); uint objectID = data.ReadUInt32(); string field = DataObject.GetTableName(type) + "_ID"; DataObject[] objs = DataServer.Database.SelectObjects(type, field + " = '" + objectID + "'"); if (objs.Length == 0) { throw new Exception("Requested objectID " + objectID + " for " + str + " didn't exist!"); } DataServer.Database.DeleteObject(objs[0]); } catch (Exception e) { Console.WriteLine("Error in OnDeleteDBObject!"); Console.WriteLine(e); } }
static void OnCreateDBObject(WorldConnection connection, WORLDMSG msgID, BinReader data) { try { int requestID = data.ReadInt32(); string str = data.ReadString(); Type type = dbTypes.GetType(str, true); DBObject obj = (DBObject)Activator.CreateInstance(type); DataServer.Database.AddNewObject(obj); WorldPacket pkg = new WorldPacket(WORLDMSG.CREATE_DBOBJECT_REPLY); pkg.Write(requestID); pkg.Write(str); pkg.Write(obj.ObjectId); connection.Send(pkg); } catch (Exception e) { Console.WriteLine("Error in OnCreateDBObject!"); Console.WriteLine(e); } }
public static void SetWorldServer(ClientBase worldConnection, uint[] worldMapIDs) { DBWorldMap[] worldMaps = new DBWorldMap[worldMapIDs.Length]; for (int i = 0; i < worldMapIDs.Length; i++) { worldMaps[i] = (DBWorldMap)DataServer.Database.FindObjectByKey(typeof(DBWorldMap), worldMapIDs[i]); if (worldMaps[i] == null) { throw new Exception("Missing worldmap " + worldMapIDs[i]); } if (m_worldMapServer.Contains(worldMaps[i].ObjectId)) { throw new Exception("There's already a worldserver handling worldmap " + worldMaps[i].ObjectId); } } WorldConnection server = new WorldConnection(worldConnection, worldMaps); foreach (DBWorldMap map in worldMaps) { m_worldMapServer[map.ObjectId] = server; } m_worldServers.Add(server); }
static void OnPlayerLeaveWorld(WorldConnection connection, WORLDMSG msgID, BinReader data) { LoginClient client = LoginServer.GetLoginClientByCharacterID(data.ReadUInt32()); if (client == null) { return; } if (client.IsLoggingOut) { LoginServer.RemoveCharacter(client); BinWriter pkg = LoginClient.NewPacket(SMSG.LOGOUT_COMPLETE); client.Send(pkg); client.IsLoggingOut = false; client.WorldConnection = null; } else if (client.IsChangingMap) { } else { client.Close("Kicked from worldserver."); } }