internal int TryJoin(Player plr, string password) { if (Password != password) { return(-1); } if (AutAccept) { PartyManager.CreateLink(Player, plr); } else { Waiting.Add(plr); _ = Player.Session.SendAsync(new SPartyMJoinNotify()); } return(0); }
private static async void PlayerPlrViewport(MapInfo Map, Character plr) { var pos = plr.Position; pos.Offset(15, 15); PartyManager.SendAll(plr.Party); var playerVP = from obj in Map.Players let rect = new Rectangle(obj.Position, new Size(30, 30)) where rect.Contains(pos) && obj.Player.Session.ID != plr.Player.Session.ID select obj; var PShop = (from obj in playerVP where obj.Shop.Open select obj).ToList(); var newPlr = (from obj in playerVP where obj.State == ObjectState.Regen select obj).ToList(); var existPlr = (from obj in playerVP where !plr.PlayersVP.Contains(obj.Player) && obj.State == ObjectState.Live select obj).ToList(); var deadPlr = (from obj in playerVP where obj.State == ObjectState.WaitRegen select obj.Player).ToList(); var lostPlr = (from obj in plr.PlayersVP where !playerVP.Contains(obj.Character) select obj).ToList(); plr.PlayersVP.AddRange(newPlr.Select(x => x.Player)); plr.PlayersVP.AddRange(existPlr.Select(x => x.Player)); var guildVP = newPlr .Where(x => x.Guild != null) .Select(x => new GuildViewPortDto { ID = x.Guild.Index, Number = x.Index, RelationShip = plr.Guild?.GetRelation(x.Guild) ?? GuildRelation.None, CastleState = 0, Status = x.Guild.Find(x.Name).Rank, Type = x.Guild.Type, }).ToList(); guildVP.AddRange(existPlr .Where(x => x.Guild != null) .Select(x => new GuildViewPortDto { ID = x.Guild.Index, Number = x.Index, RelationShip = plr.Guild?.GetRelation(x.Guild) ?? GuildRelation.None, CastleState = 0, Status = x.Guild.Find(x.Name).Rank, Type = x.Guild.Type, })); foreach (var it in deadPlr) { plr.PlayersVP.Remove(it); } foreach (var it in lostPlr) { plr.PlayersVP.Remove(it); } var addPlr = new List <VPCreateAbs>(); switch (Program.Season) { case 9: addPlr.AddRange(newPlr.Select(x => new VPCreateS9Dto { CharSet = x.Inventory.GetCharset(), DirAndPkLevel = (byte)((x.Direction << 4) | 0), Name = x.Name, Number = (ushort)(x.Player.Session.ID | 0x8000), Position = x.Position, TPosition = x.TPosition, ViewSkillState = x.Spells.ViewSkillStates, Player = x.Player, PentagramMainAttribute = 0, CurLife = (uint)x.Health, MaxLife = (uint)x.MaxHealth, Level = x.Level, MuunItem = 0xffff, MuunRideItem = 0xffff, MuunSubItem = 0xffff, ServerCodeOfHomeWorld = 0, })); addPlr.AddRange(existPlr.Select(x => new VPCreateS9Dto { CharSet = x.Inventory.GetCharset(), DirAndPkLevel = (byte)((x.Direction << 4) | 0), Name = x.Name, Number = (ushort)x.Player.Session.ID, Position = x.Position, TPosition = x.TPosition, ViewSkillState = x.Spells.ViewSkillStates, Player = x.Player, PentagramMainAttribute = 0, CurLife = (uint)x.Health, MaxLife = (uint)x.MaxHealth, Level = x.Level, MuunItem = 0xffff, MuunRideItem = 0xffff, MuunSubItem = 0xffff, ServerCodeOfHomeWorld = 0, })); break; default: addPlr.AddRange(newPlr.Select(x => new VPCreateDto { CharSet = x.Inventory.GetCharset(), DirAndPkLevel = (byte)((x.Direction << 4) | 0), Name = x.Name, Number = (ushort)(x.Player.Session.ID | 0x8000), Position = x.Position, TPosition = x.TPosition, ViewSkillState = x.Spells.ViewSkillStates, Player = x.Player })); addPlr.AddRange(existPlr.Select(x => new VPCreateDto { CharSet = x.Inventory.GetCharset(), DirAndPkLevel = (byte)((x.Direction << 4) | 0), Name = x.Name, Number = (ushort)x.Player.Session.ID, Position = x.Position, TPosition = x.TPosition, ViewSkillState = x.Spells.ViewSkillStates, Player = x.Player })); break; } switch (Program.Season) { case 9: if (addPlr.Any()) { await plr.Player.Session.SendAsync(new SViewPortCreateS9 { ViewPort = addPlr.Select(x => (VPCreateS9Dto)x).ToArray() }); } break; default: if (addPlr.Any()) { await plr.Player.Session.SendAsync(new SViewPortCreate { ViewPort = addPlr.Select(x => (VPCreateDto)x).ToArray() }); } break; } if (lostPlr.Any()) { await plr.Player.Session.SendAsync(new SViewPortDestroy(lostPlr.Select(x => new VPDestroyDto((ushort)x.Session.ID)).ToArray())); } if (PShop.Any()) { await plr.Player.Session.SendAsync(new SViewPortPShop { VPShops = PShop.Select(x => new VPPShopDto { btName = x.Shop.Name.GetBytes(), wzNumber = x.Index.ShufleEnding() }).ToArray() }); } if (guildVP.Any()) { await plr.Player.Session.SendAsync(new SGuildViewPort { Guilds = guildVP.ToArray() }); } }
static void Main(string[] args) { Predicate <GSSession> MustNotBeLoggedIn = session => session.Player.Status == LoginStatus.NotLogged; Predicate <GSSession> MustBeLoggedIn = session => session.Player.Status == LoginStatus.Logged; Predicate <GSSession> MustBePlaying = session => session.Player.Status == LoginStatus.Playing; Predicate <GSSession> MustBeLoggedOrPlaying = session => session.Player.Status == LoginStatus.Logged || session.Player.Status == LoginStatus.Playing; string output = "{Timestamp: HH:mm:ss} [{Level} {SourceContext}][{AID}:{AUser}] {Message}{NewLine}{Exception}"; Log.Logger = new LoggerConfiguration() .Destructure.ByTransforming <IPEndPoint>(endPoint => endPoint.ToString()) .Destructure.ByTransforming <EndPoint>(endPoint => endPoint.ToString()) .WriteTo.RollingFile("GameServer_{Date}.txt", outputTemplate: output) .WriteTo.Console(outputTemplate: output) .MinimumLevel.Debug() .CreateLogger(); ServerMessages = new ServerMessages(); ServerMessages.LoadMessages("./Data/Lang/ServerMessages(es).xml"); if (!File.Exists("./Server.xml")) { Log.Logger.Error(ServerMessages.GetMessage(Messages.Server_Cfg)); ResourceLoader.XmlSaver("./Server.xml", new ServerInfoDto { AutoRegistre = true, Code = 0, ConnectServerIP = "127.0.0.1", DataBase = "MuOnline", DBIp = "127.0.0.1", BDUser = "******", DBPassword = "", DropRate = 60, Experience = 10, IP = "127.0.0.1", Name = "GameServer", Port = 55901, Serial = "Serial", Show = 1, Version = "10203", Zen = 10, }); Task.Delay(10000); return; } var xml = ResourceLoader.XmlLoader <ServerInfoDto>("./Server.xml"); ServerMessages.LoadMessages($"./Data/Lang/ServerMessages({xml.Lang}).xml"); Console.Title = ServerMessages.GetMessage(Messages.Server_Title, xml.Code, xml.Name, xml.Version, xml.Serial, xml.DataBase); ConnectionString = $"Server={xml.DBIp};port=3306;Database={xml.DataBase};user={xml.BDUser};password={xml.DBPassword};Convert Zero Datetime=True;"; SimpleModulus.LoadDecryptionKey("./Data/Dec1.dat"); SimpleModulus.LoadEncryptionKey("./Data/Enc2.dat"); byte[] key = { 0x44, 0x9D, 0x0F, 0xD0, 0x37, 0x22, 0x8F, 0xCB, 0xED, 0x0D, 0x37, 0x04, 0xDE, 0x78, 0x00, 0xE4, 0x33, 0x86, 0x20, 0xC2, 0x79, 0x35, 0x92, 0x26, 0xD4, 0x37, 0x37, 0x30, 0x98, 0xEF, 0xA4, 0xDE }; PacketEncrypt.Initialize(key); var ip = new IPEndPoint(IPAddress.Parse(xml.IP), xml.Port); var csIP = new IPEndPoint(IPAddress.Parse(xml.ConnectServerIP), 44405); AutoRegistre = xml.AutoRegistre; ServerCode = (ushort)xml.Code; Experience = xml.Experience; Zen = xml.Zen; DropRate = xml.DropRate; Season12 = xml.Rijndael; var mh = new MessageHandler[] { new FilteredMessageHandler <GSSession>() .AddHandler(new AuthServices()) .AddHandler(new GlobalServices()) .AddHandler(new GameServices()) .AddHandler(new CashShopServices()) .AddHandler(new EventServices()) .AddHandler(new QuestSystemServices()) .AddHandler(new GuildServices()) .AddHandler(new AntiHackServices()) .RegisterRule <CIDAndPass>(MustNotBeLoggedIn) .RegisterRule <CCharacterList>(MustBeLoggedIn) .RegisterRule <CCharacterMapJoin>(MustBeLoggedIn) .RegisterRule <CCharacterMapJoin2>(MustBeLoggedIn) .RegisterRule <CCloseWindow>(MustBePlaying) .RegisterRule <CDataLoadOK>(MustBePlaying) .RegisterRule <CAction>(MustBePlaying) }; var mf = new MessageFactory[] { new AuthMessageFactory(), new GlobalMessageFactory(), new GameMessageFactory(), new CashShopMessageFactory(), new EventMessageFactory(), new QuestSystemMessageFactory(), new GuildMessageFactory(), new AntiHackMessageFactory(), }; server = new WZGameServer(ip, mh, mf, xml.Rijndael); server.ClientVersion = xml.Version; server.ClientSerial = xml.Serial; var cmh = new MessageHandler[] { new FilteredMessageHandler <CSClient>() .AddHandler(new CSServices()) }; var cmf = new MessageFactory[] { new CSMessageFactory() }; try { ResourceCache.Initialize(".\\Data"); MonstersMng.Initialize(); MonstersMng.Instance.LoadMonster("./Data/Monsters/Monster.txt"); EventInitialize(); MonstersMng.Instance.LoadSetBase("./Data/Monsters/MonsterSetBase.txt"); GuildManager.Initialize(); PartyManager.Initialzie(400); DuelSystem.Initialize(); SubSystem.Initialize(); Marlon.Initialize(); }catch (MySql.Data.MySqlClient.MySqlException ex) { Log.Error(ex, ServerMessages.GetMessage(Messages.Server_MySQL_Error)); //Migrate(null, new EventArgs()); //Log.Information("Server needs restart to reload all changes"); Task.Delay(10000); } catch (Exception ex) { Log.Error(ex, ServerMessages.GetMessage(Messages.Server_Error)); } try { client = new CSClient(csIP, cmh, cmf, (ushort)xml.Code, server, (byte)xml.Show); }catch (Exception) { Log.Error(ServerMessages.GetMessage(Messages.Server_CSServer_Error)); } Log.Information(ServerMessages.GetMessage(Messages.Server_Disconnecting_Accounts)); try { using (var db = new GameContext()) { var accs = from acc in db.Accounts where acc.IsConnected && acc.ServerCode == xml.Code select acc; foreach (var acc in accs) { acc.IsConnected = false; } db.Accounts.UpdateRange(accs); db.SaveChanges(); } }catch (Exception) { Log.Error("MySQL unavailable."); Task.Delay(15000); return; } Log.Information(ServerMessages.GetMessage(Messages.Server_Ready)); Handler.AddCommand(new Command <GSSession>("exit", Close)) .AddCommand(new Command <GSSession>("quit", Close)) .AddCommand(new Command <GSSession>("stop", Close)) .AddCommand(new Command <GSSession>("reload") .AddCommand(new Command <GSSession>("shops", (object a, CommandEventArgs b) => ResourceCache.Instance.ReloadShops())) .AddCommand(new Command <GSSession>("gates", (object a, CommandEventArgs b) => ResourceCache.Instance.ReloadGates()))) .AddCommand(new Command <GSSession>("create") .AddCommand(new Command <GSSession>("movereq", DumpMoveReq))) .AddCommand(new Command <GSSession>("db") .AddCommand(new Command <GSSession>("migrate", Migrate)) .AddCommand(new Command <GSSession>("create", Create)) .AddCommand(new Command <GSSession>("delete", Delete))) .AddCommand(new Command <GSSession>("!", (object a, CommandEventArgs b) => GlobalAnoucement(b.Argument)).SetPartial()) .AddCommand(new Command <GSSession>("/").SetPartial() .AddCommand(new Command <GSSession>("add").SetPartial() .AddCommand(new Command <GSSession>("str", Character.AddStr)) .AddCommand(new Command <GSSession>("agi", Character.AddAgi)) .AddCommand(new Command <GSSession>("vit", Character.AddVit)) .AddCommand(new Command <GSSession>("ene", Character.AddEne)) .AddCommand(new Command <GSSession>("cmd", Character.AddCmd))) .AddCommand(new Command <GSSession>("set") .AddCommand(new Command <GSSession>("hp", (object a, CommandEventArgs b) => ((GSSession)a).Player.Character.Health = float.Parse(b.Argument))) .AddCommand(new Command <GSSession>("zen", (object a, CommandEventArgs b) => ((GSSession)a).Player.Character.Money = uint.Parse(b.Argument))) .AddCommand(new Command <GSSession>("exp", (object a, CommandEventArgs b) => ((GSSession)a).Player.Character.Experience = uint.Parse(b.Argument)))) .AddCommand(new Command <GSSession>("levelup", LevelUp)) /*.AddCommand(new Command<GSSession>("post"))*/) //.AddCommand(new Command<GSSession>("~").SetPartial()) /*.AddCommand(new Command<GSSession>("]").SetPartial())*/; while (true) { var input = Console.ReadLine(); if (input == null) { break; } Handler.ProcessCommands(null, input); } }
private static async void PlayerPlrViewport(MapInfo Map, Character plr) { var pos = plr.Position; pos.Offset(15, 15); List <Character> newPlr, PShop, existPlr; List <Player> deadPlr, lostPlr; List <GuildViewPortDto> guildVP; List <VPGensDto> gensVP; PartyManager.SendAll(plr.Party); lock (plr.PlayersVP) { var playerVP = from obj in Map.Players let rect = new Rectangle(obj.Position, new Size(30, 30)) where rect.Contains(pos) && obj.Player.Session.ID != plr.Player.Session.ID select obj; PShop = (from obj in playerVP where obj.Shop.Open select obj).ToList(); newPlr = (from obj in playerVP where obj.State == ObjectState.Regen select obj).ToList(); existPlr = (from obj in playerVP where (!plr.PlayersVP.Contains(obj.Player) || obj.Player.Character.Change) && obj.State == ObjectState.Live select obj).ToList(); deadPlr = (from obj in playerVP where obj.State == ObjectState.WaitRegen select obj.Player).ToList(); lostPlr = (from obj in plr.PlayersVP where !playerVP.Contains(obj.Character) select obj).ToList(); plr.PlayersVP.AddRange(newPlr.Select(x => x.Player)); plr.PlayersVP.AddRange(existPlr.Select(x => x.Player)); guildVP = newPlr .Where(x => x.Guild != null) .Select(x => new GuildViewPortDto { ID = x.Guild.Index, Number = x.Index, RelationShip = plr.Guild?.GetRelation(x.Guild) ?? GuildRelation.None, CastleState = 0, Status = x.Guild.Find(x.Name).Rank, Type = x.Guild.Type, }).ToList(); guildVP.AddRange(existPlr .Where(x => x.Guild != null) .Select(x => new GuildViewPortDto { ID = x.Guild.Index, Number = x.Index, RelationShip = plr.Guild?.GetRelation(x.Guild) ?? GuildRelation.None, CastleState = 0, Status = x.Guild.Find(x.Name).Rank, Type = x.Guild.Type, })); gensVP = newPlr .Where(x => x.Gens.Influence != GensType.None) .Select(x => new VPGensDto { Influence = x.Gens.Influence, iGensClass = x.Gens.Class, iGensRanking = x.Gens.Ranking, iContributePoint = x.Gens.Contribution, wzNumber = x.Index.ShufleEnding() }).ToList(); gensVP.AddRange(existPlr.Where(x => x.Gens.Influence != GensType.None) .Select(x => new VPGensDto { Influence = x.Gens.Influence, iGensClass = x.Gens.Class, iGensRanking = x.Gens.Ranking, iContributePoint = x.Gens.Contribution, wzNumber = x.Index.ShufleEnding() })); foreach (var it in deadPlr) { plr.PlayersVP.Remove(it); } foreach (var it in lostPlr) { plr.PlayersVP.Remove(it); } } var addPlr = new List <VPCreateAbs>(); var typeBase = Program.Season switch { ServerSeason.Season16Kor => typeof(VPCreateS16KorDto), ServerSeason.Season12Eng => typeof(VPCreateS12Dto), ServerSeason.Season9Eng => typeof(VPCreateS9Dto), _ => typeof(VPCreateDto), }; foreach (var x in newPlr) { var obj = Activator.CreateInstance(typeBase) as VPCreateAbs; AssignVP(obj, x, true); addPlr.Add(obj); } foreach (var x in existPlr) { var obj = Activator.CreateInstance(typeBase) as VPCreateAbs; AssignVP(obj, x, false); addPlr.Add(obj); } var msg = VersionSelector.CreateMessage <SViewPortCreate>(addPlr); await plr.Player.Session.SendAsync(msg); if (lostPlr.Any()) { await plr.Player.Session.SendAsync(new SViewPortDestroy(lostPlr.Select(x => new VPDestroyDto((ushort)x.Session.ID)).ToArray())); } if (PShop.Any()) { await plr.Player.Session.SendAsync(new SViewPortPShop { VPShops = PShop.Select(x => new VPPShopDto { btName = x.Shop.Name.GetBytes(), wzNumber = x.Index.ShufleEnding() }).ToArray() }); } if (guildVP.Any()) { await plr.Player.Session.SendAsync(new SGuildViewPort { Guilds = guildVP.ToArray() }); } if (gensVP.Any()) { await plr.Player.Session.SendAsync(new SViewPortGens { VPGens = gensVP.ToArray() }); } }