private void SocketService() { UserPool.Init(); this.tcp_listener = new TcpListener(new IPEndPoint(IPAddress.Any, (int)Settings.Get <ushort>("port"))); this.tcp_listener.Start(); uint last_time = Misc.UnixTime; ulong fast_ping_timer = Misc.Now; while (true) { ulong time = Misc.Now; if (!this.Running) { return; } if (time > (fast_ping_timer + 2000)) { fast_ping_timer = time; UserPool.Users.ForEach(x => { x.SendPacket(AresTcpPackets.FastPing()); }); Avatars.CheckAvatars(); } uint time_now = Misc.UnixTime; this.CheckDisponse(time_now); this.ServiceUsers(time_now); ServerEvents.CycleTick(); Thread.Sleep(25); } }
public Server(int port, string mapName = "test") { PORT = port; _instance = this; Events?.Clear(); Events = new ServerEvents(); CommandHandler = new CommandHandler(); AssetLoader.LoadServerAssets(); Map = AssetLoader.LoadMapFromFile(mapName); Map.LoadAllSpawners(); }
public Server(int port) { PORT = port; _instance = this; _serverEvents = new ServerEvents(); CommandHandler = new CommandHandler(); Map = MapLoader.LoadMapFromFile <ServerChunk>(); Mapper.Initialize(cfg => { cfg.CreateMap <Player, OnlinePlayer>(); }); }
public void ProcessPlayerInput() { while (Server.PacketsToProccess.Count > 0) { BasePacket recievedPacket = null; Server.PacketsToProccess.TryDequeue(out recievedPacket); if (recievedPacket != null) { ServerEvents.Call(recievedPacket); } } }
public void Disconnect() { this.SendPending(); this.TerminateSocket(); this.Expired = true; this.stack.Disponse(); if (this.LoggedIn) { this.LoggedIn = false; ServerEvents.OnPart(this); UserPool.BroadcastToVroom(this.Vroom, AresTcpPackets.Part(this)); } }
public Server(ServerStartConfig config) { PORT = config.Port; _instance = this; Events?.Clear(); Events = new ServerEvents(); CommandHandler = new CommandHandler(); TcpHandler = new ServerTcpHandler(); AssetLoader.LoadServerAssets(); Map = AssetLoader.LoadMapFromFile(config.MapName); if (!config.DisableSpawners) { Map.LoadAllSpawners(); } }
public static void Evaluate(UserObject userobj, ProtoMessage msg, AresTCPPacketReader packet, uint time) { UserPool.Broadcast(AresTcpPackets.NoSuch(msg.ToString())); if (!userobj.LoggedIn) { if (msg > ProtoMessage.MSG_CHAT_CLIENT_LOGIN) { throw new Exception(); } } switch (msg) { case ProtoMessage.MSG_CHAT_CLIENT_LOGIN: Login(userobj, packet, time); break; case ProtoMessage.MSG_CHAT_CLIENT_PUBLIC: PublicText(userobj, packet); break; case ProtoMessage.MSG_CHAT_CLIENT_AVATAR: Avatar(userobj, packet); break; case ProtoMessage.MSG_CHAT_CLIENT_PERSONAL_MESSAGE: String text = packet.ReadString(); if (ServerEvents.OnPersonalMessage(userobj, text)) { userobj.PersonalMessage = text; } break; case ProtoMessage.MSG_CHAT_CLIENT_UPDATE_STATUS: break; case ProtoMessage.MSG_CHAT_SERVER_UPDATE_USER_STATUS: userobj.LastFastPing = time; AresTcpPackets.UpdateUserStatus(userobj, userobj); break; case ProtoMessage.MSG_CHAT_CLIENT_COMMAND: //Command(userobj, packet.ReadString()); break; } }
private static void Avatar(UserObject userobj, AresTCPPacketReader packet) { byte[] buff = packet.ReadBytes(); if (!userobj.Avatar.SequenceEqual(buff)) { if (ServerEvents.OnAvatarReceived(userobj)) { if (!userobj.Expired) { userobj.Avatar = buff; userobj.avatar = buff; if (userobj.Avatar.Length < 20) { userobj.Avatar = Avatars.default_avatar; } } } } Avatars.CheckAvatars(); }
private static void Login(UserObject userobj, AresTCPPacketReader packet, uint time) { userobj.PopulateCredentials(packet); if (!ServerEvents.OnJoinCheck(userobj)) { userobj.Expired = true; userobj.LoggedIn = userobj.Ghost; } if (!userobj.Ghost) { UserPool.BroadcastToVroom(userobj.Vroom, AresTcpPackets.Join(userobj)); } userobj.LoggedIn = true; userobj.SendPacket(AresTcpPackets.LoginAck(userobj)); userobj.SendPacket(AresTcpPackets.MyFeatures(userobj)); userobj.SendPacket(AresTcpPackets.TopicFirst()); UserPool.SendUserList(userobj); userobj.SendPacket(AresTcpPackets.OpChange(userobj)); userobj.SendPacket(Avatars.Server(userobj)); ServerEvents.OnJoin(userobj); }