private void Awake() { if (Instance == null) { Instance = this; } }
public VanillaWorld(int portNumber, int maxConnections) { DBC = new DBCLibrary(); WorldDatabase = new DatabaseUnitOfWork <WorldDatabase>(); CharacterDatabase = new DatabaseUnitOfWork <CharacterDatabase>(); Server = new WorldServer(this); Components.Add(new ActionButtonComponent(this)); Components.Add(new AuthComponent(this)); Components.Add(new CharacterComponent(this)); Components.Add(new ChatMessageComponent(this)); Components.Add(new WeatherComponent(this)); Components.Add(new EntityComponent(this)); Components.Add(new GameObjectComponent(this)); Components.Add(new LoginComponent(this)); Components.Add(new LogoutComponent(this)); Components.Add(new MailComponent(this)); Components.Add(new MiscComponent(this)); Components.Add(new PlayerMovementComponent(this)); Components.Add(new SpellComponent(this)); ChatCommands = new ChatCommandParser(); Server.Start(portNumber, maxConnections); var accountCreator = new AccountCreator(); accountCreator.CreateAccount("andrew", "password"); accountCreator.CreateAccount("lucas", "password"); }
static void OnSpawn(int msgID, BinReader data) { uint charID = data.ReadUInt32(); uint creatureID = data.ReadUInt32(); int displayID = data.ReadInt32(); WorldClient client = WorldServer.GetClientByCharacterID(charID); if (client == null) { return; } DBCreature creature = (DBCreature)DBManager.GetDBObject(typeof(DBCreature), creatureID); MonsterBase unit = new MonsterBase(creature); unit.Position = client.Player.Position; unit.Facing = client.Player.Facing; unit.DisplayID = displayID; unit.MaxHealth = unit.Health = 100; unit.MaxPower = unit.Power = 100; unit.PowerType = POWERTYPE.MANA; unit.Level = new Random().Next(10); unit.Faction = 0; client.Player.MapTile.Map.Enter(unit); unit.StartGetNodes(); }
public static bool CanAccessToWorld(AuthClient client, WorldServer world) { if (world == null) { return(false); } if (world.Status != ServerStatusEnum.ONLINE) { return(false); } if (!client.UserGroup.CanAccessWorld(world)) { return(false); } if (world.CharsCount >= world.CharCapacity) { return(false); } if (world.RequireSubscription && (client.Account.SubscriptionEnd < DateTime.Now)) { return(false); } return(true); }
//950 Move public static void HandleMove(BigEndianReader reader, WorldClient client, WorldServer server) { GameMapMovementRequestMessage message = new GameMapMovementRequestMessage(); message.Unpack(reader); client.Send(new GameMapMovementMessage(message.keyMovements, 1)); }
protected void initialWorldChunkLoad() { int i = 16; int j = 4; int k = 192; int l = 625; int i1 = 0; //Debug.Log ("menu.generatingTerrain"); int j1 = 0; //Debug.Log ("Preparing start region for level {0}, j1"); WorldServer worldserver = worldServers[j1]; BlockPos blockPos = worldserver.getSpawnPoint(); long k1 = getCurrentTimeMillis(); for (int x = -MinecraftConfig.loadSize / 2; x < MinecraftConfig.loadSize / 2; x += MinecraftConfig.chunkSize) { for (int z = -MinecraftConfig.loadSize / 2; z < MinecraftConfig.loadSize / 2; z += MinecraftConfig.chunkSize) { long j2 = getCurrentTimeMillis(); if (j2 - k1 > 1000L) { Debug.LogFormat("Preparing spawn area {0}", i1 * 100 / ((MinecraftConfig.loadSize / MinecraftConfig.chunkSize) * (MinecraftConfig.loadSize / MinecraftConfig.chunkSize))); k1 = j2; } ++i1; worldserver.theChunkProviderServer.loadChunk(blockPos.x + x >> MinecraftConfig.chunkBitSize, blockPos.z + z >> MinecraftConfig.chunkBitSize); } } }
private static void Main(string[] args) { WorldServer server = new WorldServer(); if (!Debugger.IsAttached) { try { server.Initialize(); server.Start(); GC.Collect(); while (true) { Thread.Sleep(5000); } } catch (Exception e) { server.HandleCrashException(e); } finally { server.Shutdown(); } return; } server.Initialize(); server.Start(); GC.Collect(); while (true) { Thread.Sleep(5000); } }
public static void HandleServerSelectionMessage(AuthClient client, ServerSelectionMessage message) { WorldServer serverById = Singleton <WorldServerManager> .Instance.GetServerById((int)message.serverId); if (serverById == null) { ConnectionHandler.SendSelectServerRefusedMessage(client, serverById, ServerConnectionErrorEnum.SERVER_CONNECTION_ERROR_NO_REASON); } else { if (serverById.Status != ServerStatusEnum.ONLINE) { ConnectionHandler.SendSelectServerRefusedMessage(client, serverById, ServerConnectionErrorEnum.SERVER_CONNECTION_ERROR_DUE_TO_STATUS); } else { if (serverById.RequiredRole > client.Account.Role) { ConnectionHandler.SendSelectServerRefusedMessage(client, serverById, ServerConnectionErrorEnum.SERVER_CONNECTION_ERROR_ACCOUNT_RESTRICTED); } else { ConnectionHandler.SendSelectServerData(client, serverById); } } } }
public static void SendSelectServerData(AuthClient client, WorldServer world) { /* Check if is null */ if (world == null) { return; } client.LookingOfServers = false; /* Bind Ticket */ client.Account.Ticket = new AsyncRandom().RandomString(32); AccountManager.Instance.CacheAccount(client.Account); client.Account.LastConnection = DateTime.Now; client.Account.LastConnectedIp = client.UserGroup.Role == RoleEnum.Administrator ? "127.0.0.1" : client.IP; client.Account.LastConnectionWorld = world.Id; client.SaveNow(); client.Send(new SelectedServerDataMessage( (short)world.Id, world.Address, world.Port, (client.UserGroup.Role >= world.RequiredRole || client.UserGroup.AvailableServers.Contains(world.Id)), Encoding.ASCII.GetBytes(client.Account.Ticket).Select(x => (sbyte)x))); client.Disconnect(); }
static void OnGroupCreate(int msgID, BinReader data) { Console.WriteLine("Creating Group"); uint charID = data.ReadUInt32(); WorldClient client = WorldServer.GetClientByCharacterID(charID); uint leaderID = data.ReadUInt32(); WorldClient leader = WorldServer.GetClientByCharacterID(leaderID); if (leader == null) { Console.WriteLine("Leader not found"); } if (leader.Player.Group == null) { leader.Player.Group = new GroupObject(client.Player, leader.Player); } else { leader.Player.Group.AddMember(client.Player); } if (leader.Player.Group == null) { Console.WriteLine("Error creating group"); } client.Player.Group = leader.Player.Group; leader.Player.IsLeader = true; client.Player.Group.LeaderGUID = leader.Player.GUID; Console.WriteLine("Groups assigned"); client.Player.Group.SendGroupList(); }
public static void SendServerStatusUpdateMessage(AuthClient client, WorldServer world) { if (world != null) { client.Send(new ServerStatusUpdateMessage(WorldServerManager.Instance.GetServerInformation(client, world))); } }
static void OnSpawnCircle(int msgID, BinReader data) { uint charID = data.ReadUInt32(); uint creatureID = data.ReadUInt32(); int displayID = data.ReadInt32(); WorldClient client = WorldServer.GetClientByCharacterID(charID); if (client == null) { return; } DBCreature creature = (DBCreature)DBManager.GetDBObject(typeof(DBCreature), creatureID); float ypos = client.Player.Position.Y; float xpos = client.Player.Position.X; float zpos = client.Player.Position.Z + 50.0f; for (int nIndex = 18; nIndex <= 378; nIndex += 18) { double theta = DegreeToRadians((double)nIndex); double x = 10.0 * Math.Cos(theta) + xpos; double y = 10.0 * Math.Sin(theta) + ypos; UnitBase unit = GetNewUnit(creature, displayID); unit.Position = new Vector((float)x, (float)y, zpos); unit.Facing = GetFacing(unit.Position, client.Player.Position); client.Player.MapTile.Map.Enter(unit); } }
static void OnSetSelection(int msgID, BinReader data) { uint CharID = data.ReadUInt32(); ulong guid = data.ReadUInt64(); WorldClient client = WorldServer.GetClientByCharacterID(CharID); if (guid == 0) { client.Player.Selection = null; } else { WorldObject obj = null; if ((obj = ObjectManager.GetWorldObject(OBJECTTYPE.PLAYER, guid)) == null) { if ((obj = ObjectManager.GetWorldObject(OBJECTTYPE.UNIT, guid)) == null) { obj = ObjectManager.GetWorldObject(OBJECTTYPE.GAMEOBJECT, guid); } // else //Chat.System(client, "Selected mob: " + ((UnitBase)obj).Name + " - HP: " + ((UnitBase)obj).Health); } // else //Chat.System(client, "Selected player: " + ((PlayerObject)obj).Name + " - HP: " + ((PlayerObject)obj).Health); client.Player.Selection = obj; } client.Player.UpdateData(); }
private static void RestartLoop() { while (true) { Thread.Sleep(1000); if (LoginServer.RestartServer) { try { Console.WriteLine("Stopping server for restart!"); WorldServer.Stop(); localWorldServerStarted = false; StopLoginServer(); Thread.Sleep(3000); } catch { } finally { DebugLogger.Log("Restarted the server..."); Process.Start("Loader.exe", "-lr"); Thread.Sleep(500); // Collect all trash GC.Collect(); // Just exit the program!! Environment.Exit(0); } } } }
private static void DrawLightFramebuffer(WorldServer world, Matrix4 viewProjectionInv, Frustum viewFrustum) { //TODO: Lighting? /* * GL.Disable(EnableCap.DepthTest); * GL.Disable(EnableCap.CullFace); * GL.Enable(EnableCap.Blend); * GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One); * * ClientResources.LightFramebuffer.Bind(); * ClientResources.LightFramebuffer.Clear(Color4.Black); * * ClientResources.PointLightShader.Bind(); * GL.UniformMatrix4(0, false, ref viewProjectionInv); * * * foreach (var light in world.Lights.Select(light => light as PointLight)) * { * if (light == null || !viewFrustum.SpehereIntersection(light.Position, light.Range)) continue; * GL.Uniform3(4, light.Position); * GL.Uniform3(5, light.Color); * GL.Uniform1(6, light.Range); * ClientResources.ScreenRectVao.Draw(); * } * * ClientResources.LightFramebuffer.Unbind(Program.Window.Width, Program.Window.Height); * * GL.Disable(EnableCap.Blend); */ }
public void DisconnectClientsUsingAccount(Account account) { AuthClient[] array = ServerBase <AuthServer> .Instance.FindClients((AuthClient entry) => entry.Account != null && entry.Account.Id == account.Id).ToArray <AuthClient>(); AuthClient[] array2 = array; for (int i = 0; i < array2.Length; i++) { AuthClient authClient = array2[i]; authClient.Disconnect(); } if (account.LastConnectionWorld.HasValue) { WorldServer serverById = Singleton <WorldServerManager> .Instance.GetServerById(account.LastConnectionWorld.Value); if (serverById != null && serverById.Connected && serverById.IPCClient != null) { serverById.IPCClient.SendRequest <DisconnectedClientMessage>(new DisconnectClientMessage(account.Id) , delegate(DisconnectedClientMessage msg) { }, delegate(IPCErrorMessage error) { }); } } }
/// <summary> /// Create a new world record and save it /// directly in database. /// </summary> public WorldServer CreateWorld(WorldServerData worldServerData) { var record = new WorldServer { Id = worldServerData.Id, Name = worldServerData.Name, RequireSubscription = worldServerData.RequireSubscription, RequiredRole = worldServerData.RequiredRole, CharCapacity = worldServerData.Capacity, ServerSelectable = true, Address = worldServerData.Address, Port = worldServerData.Port, }; if (!m_realmlist.TryAdd(record.Id, record)) { throw new Exception("Server already registered"); } Database.Insert(record); logger.Info(string.Format("World {0} created", worldServerData.Name)); return(record); }
static LocalClientBase StartLocalWorldServer() { WorldServerConfig config = new WorldServerConfig(m_configDir + "worldserver.config"); if (config.Document["WorldServerConfig"] == null) { config.SetDefaultValues(); } XmlNodeList list = config.Document["WorldServerConfig"].SelectNodes("descendant::ScriptReference"); foreach (XmlNode node in list) { WorldServer.AddScriptReference(node.InnerText); } if (WorldServer.LoadWorldScripts(config.Scripts) == false) { return(null); } LocalClientBase c1 = new LocalClientBase(); LocalClientBase c2 = new LocalClientBase(); c1.SetRemoteClient(c2); c2.SetRemoteClient(c1); WorldServer.Start(c2); localWorldServerStarted = true; Console.WriteLine("Local Worldserver started."); return(c1); }
//CONSOLE MSG public static void HandleConsole(BigEndianReader reader, WorldClient client, WorldServer server) { AdminCommandMessage message = new AdminCommandMessage(); message.Unpack(reader); string[] args = message.content.Split(' '); switch (args[0]) { case "ADDITEM": int Id = int.Parse(args[1]); client.Send(new ObjectAddedMessage(new ObjectItem( 63, (short)Id, 0, false, new ObjectEffect[0], 0, 1 ))); break; case "TPMAP": client.Send(new CurrentMapMessage(int.Parse(args[1]))); break; default: break; } }
static void Main() { DebugLogger.Global.MessageLogged += Console.WriteLine; //ClientAcceptor ClientAcceptor clientAcceptor = new ClientAcceptor(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 3000)); //World servers WorldServer[] worldServers = new WorldServer[] { new WorldServer(1, new IPEndPoint(IPAddress.Parse("127.0.0.1"), 4000), new IPEndPoint(IPAddress.Parse("127.0.0.1"), 4000)), new WorldServer(2, new IPEndPoint(IPAddress.Parse("127.0.0.1"), 4001), new IPEndPoint(IPAddress.Parse("127.0.0.1"), 4001)) }; //General servers GeneralServer[] generalServers = new GeneralServer[] { new GeneralServer(1, new IPEndPoint(IPAddress.Parse("127.0.0.1"), 4500), new IPEndPoint(IPAddress.Parse("127.0.0.1"), 4500)), new GeneralServer(2, new IPEndPoint(IPAddress.Parse("127.0.0.1"), 4501), new IPEndPoint(IPAddress.Parse("127.0.0.1"), 4501)) }; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MasterServerWindow(clientAcceptor, worldServers, generalServers)); }
public ClarionAgent(WorldServer nws, String creature_ID, String creature_Name) { worldServer = nws; // Initialize the agent CurrentAgent = World.NewAgent("Current Agent"); //mind = new Mind(); //mind.Show(); creatureId = creature_ID; creatureName = creature_Name; // Initialize Input Information inputWallAhead = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_WALL_AHEAD); inputFoodAhead = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_FOOD_AHEAD); inputLeafletJewelAhead = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_LEAFLET_JEWEL_AHEAD); inputNonLeafletJewelAhead = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_NON_LEAFLET_JEWEL_AHEAD); inputCloseObjectAhead = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_CLOSE_OBJECT_AHEAD); inputHasCompletedLeaflet = World.NewDimensionValuePair(SENSOR_VISUAL_DIMENSION, DIMENSION_HAS_COMPLETED_LEAFLET); // Initialize Output actions outputRotateClockwise = World.NewExternalActionChunk(CreatureActions.ROTATE_CLOCKWISE.ToString()); outputGoAhead = World.NewExternalActionChunk(CreatureActions.GO_AHEAD.ToString()); outputEat = World.NewExternalActionChunk(CreatureActions.EAT.ToString()); outputHide = World.NewExternalActionChunk(CreatureActions.HIDE.ToString()); outputSack = World.NewExternalActionChunk(CreatureActions.SACK.ToString()); outputStop = World.NewExternalActionChunk(CreatureActions.STOP.ToString()); //Create thread to simulation runThread = new Thread(CognitiveCycle); Console.WriteLine("Agent started"); }
public ServerHandler() { _world = new WorldServer(); Thread tickThread = new Thread(TickThread); tickThread.Start(); _server = new FeatherTcpServer <GenericMessage>(); _server.OnClientConnected += (endPoint) => { if (!_entities.Keys.Contains(endPoint)) { var e = new Entity(); _entities.TryAdd(endPoint, e); var gm = new GenericMessage(); gm.WriteUnsignedInteger(0); gm.WriteGuid(e.ID); _server.SendToAsync(endPoint, gm); } Console.WriteLine($"{endPoint} connected."); }; _server.OnClientDisconnected += (endPoint, reason) => { _entities.TryRemove(endPoint, out var removed); Console.WriteLine($"{endPoint} disconnected."); }; _server.OnMessageReceived += (endPoint, message) => { var id = message.ReadUnsignedInteger(); if (_entities.TryGetValue(endPoint, out var entity)) { if (id == 1) { ProcessPlayerData(entity, message); } if (id == 2) { SendChunkDataTo(endPoint, message); } } }; _server.Listen(25566); Console.WriteLine("Server now listening for connections on port 25566. Press any key to halt."); Console.ReadKey(true); _server.Dispose(); }
static void OnItemVendor(int msgID, BinReader data) { uint charID = data.ReadUInt32(); uint itemId = data.ReadUInt32(); int price = data.ReadInt32(); WorldClient client = WorldServer.GetClientByCharacterID(charID); if (client == null) { return; } if (client.Player.Money < price) { Chat.System(client, "You do not have the required funds for this item"); return; } DBItem newitem = (DBItem)DBManager.GetDBObject(typeof(DBItem), itemId); if (newitem == null) { Chat.System(client, "Item not found"); return; } newitem.Template = (DBItemTemplate)DBManager.GetDBObject(typeof(DBItemTemplate), newitem.TemplateID); if (newitem.Template == null) { Chat.System(client, "Item Template not found"); return; } Console.WriteLine("Slot:" + newitem.OwnerSlot); if (newitem.OwnerSlot == 0) { newitem.OwnerSlot = client.Player.Inventory.GetOpenBackpackSlot(); } DBManager.SaveDBObject(newitem); ItemObject NewObj = (ItemObject)client.Player.Inventory.CreateItem(newitem); // client.Player.MapTile.Map.Enter(NewObj); BinWriter w = new BinWriter(); w.Write(1); w.Write((byte)0); NewObj.AddCreateObject(w, false, true); ServerPacket pkg = new ServerPacket(SMSG.COMPRESSED_UPDATE_OBJECT); byte[] compressed = ZLib.Compress(w.GetBuffer(), 0, (int)w.BaseStream.Length); pkg.Write((int)w.BaseStream.Length); pkg.Write(compressed); pkg.Finish(); client.Player.MapTile.SendSurrounding(pkg); client.Player.Money = client.Player.Money - price; client.Player.UpdateData(); // Chat.System (client, "Buy Item working on Worldserver side"); }
public void updateTimeLightAndEntities() { for (int i = 0; i < worldServers.Length; ++i) { WorldServer worldServer = worldServers [i]; worldServer.tick(); } }
public ServerProgram() { EzServerConfig loginConfig = ReadConfig("login.json"); EzServerConfig worldConfig = ReadConfig("world.json"); _loginServer = new LoginServer(loginConfig); _worldServer = new WorldServer(worldConfig); }
private static void BreakBlock(WorldServer world) { if (_blockRaytrace == null) { return; } world.SetBlock(_blockRaytrace.BlockPos, BlockRegistry.BlockAir); }
protected override void ChannelRead0(IChannelHandlerContext contex, string toDeserialize) { Channel msg; try { msg = JsonConvert.DeserializeObject <Channel>(toDeserialize); } catch (Exception ex) { Logger.Log.Error(string.Format(LogLanguage.Instance.GetMessageFromKey("UNRECOGNIZED_MASTER_PACKET"), ex)); return; } if (!IsAuthenticated) { if (msg.Password == Password) { IsAuthenticated = true; Logger.Log.Debug(string.Format(LogLanguage.Instance.GetMessageFromKey(string.Format("AUTHENTICATED_SUCCESS", _id.ToString())))); if (MasterClientListSingleton.Instance.WorldServers == null) { MasterClientListSingleton.Instance.WorldServers = new List <WorldServer>(); } try { _id = MasterClientListSingleton.Instance.WorldServers.Select(s => s.Id).Max() + 1; } catch { _id = 0; } ServerType servtype = (ServerType)System.Enum.Parse(typeof(ServerType), msg.ClientType.ToString()); if (servtype == ServerType.WorldServer) { WorldServer serv = new WorldServer { Name = msg.ClientName, Host = msg.Host, Port = msg.Port, Id = _id, ConnectedAccountsLimit = msg.ConnectedAccountsLimit, WebApi = msg.WebApi }; MasterClientListSingleton.Instance.WorldServers.Add(serv); WriteAsync(contex, msg); } contex.Flush(); } else { contex.CloseAsync(); Logger.Log.Error(string.Format(LogLanguage.Instance.GetMessageFromKey("AUTHENTICATED_ERROR"))); } } }
static void OnAccessUpdate(int msgID, BinReader data) { uint charID = data.ReadUInt32(); ACCESSLEVEL newAccessLevel = (ACCESSLEVEL)data.ReadByte(); WorldClient client = WorldServer.GetClientByCharacterID(charID); client.Player.AccessLvl = newAccessLevel; client.Player.UpdateData(); }
static void OnZoneUpdate(int msgID, BinReader data) { uint charID = data.ReadUInt32(); uint newZone = data.ReadUInt32(); WorldClient client = WorldServer.GetClientByCharacterID(charID); client.Player.Zone = newZone; client.Player.UpdateData(); }
static void Main(string[] args) { Out.Initialize(); auth = new AuthServer(); world = new WorldServer(); auth.Initialize(ip, port); ExecuteCommand(); }
public ChunkProviderServer(WorldServer worldserver, IChunkLoader ichunkloader, IChunkProvider ichunkprovider) { field_725_a = new HashSet(); id2ChunkMap = new HashMap(); field_727_f = new ArrayList(); field_724_b = new EmptyChunk(worldserver, new byte[32768], 0, 0); world = worldserver; field_729_d = ichunkloader; field_730_c = ichunkprovider; }
public void setPlayerManager(WorldServer worldserver) { playerNBTManagerObj = worldserver.func_22075_m().func_22090_d(); }