private async void Start() { try { // Get components _user = GetComponent <UserInput>(); // Load model StatusBlock.text = $"Starting"; #if ENABLE_WINMD_SUPPORT // Configure camera to return frames fitting the model input size _mediaCapturer = new MediaCapturer(); await _mediaCapturer.StartCapturing(); StatusBlock.text = $"Camera started. Running!"; // Run processing loop in separate parallel Task _isRunning = true; await Task.Run(async() => { var client = new CSClient(); while (_isRunning) { using (var videoFrame = _mediaCapturer.GetLatestFrame()) { var bitmap = videoFrame?.SoftwareBitmap; if (bitmap != null) { var data = await EncodedBytes(bitmap, Windows.Graphics.Imaging.BitmapEncoder.JpegEncoderId); var result = await client.FaceAnalysesAsync(data); StringBuilder builder = new StringBuilder(); if (result != null) { foreach (var item in result) { builder.AppendLine($"Face ID: {item.faceId}"); builder.AppendLine("Emotions"); builder.AppendLine($"Anger: {item.faceAttributes.emotion.anger}"); builder.AppendLine($"Happy: {item.faceAttributes.emotion.happiness}"); } } UnityEngine.WSA.Application.InvokeOnAppThread(() => { StatusBlock.text = builder.ToString(); }, true); } } } }); #endif } catch (Exception ex) { StatusBlock.text = $"Error init: {ex.Message}"; Debug.LogError(ex); } }
// 用户登陆尝试,调用CS模块 void Login(object currWindow) { String reply = CSClient.getInstance().SendAMsg($"{userName}_{passWord}"); if (reply != "lol") { return; } App.mainWindow = new MainWindow(); App.mainWindow.Show(); isLogging = false; }
/// <summary> /// Create a new OCPP CS client logger using the default logging delegates. /// </summary> /// <param name="CSClient">A OCPP CS client.</param> /// <param name="Context">A context of this API.</param> /// <param name="LogFileCreator">A delegate to create a log file from the given context and log file name.</param> public CSClientLogger(CSClient CSClient, String Context = DefaultContext, LogfileCreatorDelegate LogFileCreator = null) : this(CSClient, Context.IsNotNullOrEmpty() ? Context : DefaultContext, null, null, null, null, LogFileCreator : LogFileCreator) { }
public override void Load() { SelectServerScreen.Show(); ServerListUpdatedSignal.AddListener(OnServerListUpdated); CSClient.Connect(); if (CSClient.Connected) { CSClient.RequestServerList(); } else { Debug.LogError("cs seems disconnected"); } }
// 好友添加,向服务器确认ID是否合法,合法后添加好友 private void AddBtn_Click(object sender, RoutedEventArgs e) { var btn = (Button)sender; string recv = CSClient.getInstance().SendAMsg($"q{(string)btn.Tag}"); string Alias = (string)btn.ToolTip; if (Alias == null || Alias.Length == 0) { Alias = (string)btn.Tag; } switch (recv) { case "error": MessageBox.Show("添加失败"); break; case "Please send the correct message.": MessageBox.Show("不存在此用户"); break; default: foreach (var item in viewModel.addressBook.items) { if (item.UserName == (string)btn.Tag) { MessageBox.Show("此用户已经是您的好友"); return; } } Model.AddressBook.Item newItem = new AddressBook.Item() { Alias = Alias, UserName = (string)btn.Tag, isOnline = (recv != "n"), IPAddress = recv != "n" ? recv : "" }; viewModel.addressBook.items.Add(newItem); MessageBox.Show("添加成功"); // 更新界面 contactList.ItemsSource = null; contactList.ItemsSource = viewModel.addressBook.items; break; } }
// 在线状态查询按钮 private void QueryBtn_Click(object sender, RoutedEventArgs e) { var btn = (Button)sender; string recv = CSClient.getInstance().SendAMsg($"q{(string)btn.Tag}"); switch (recv) { case "error": MessageBox.Show("添加失败"); break; case "Please send the correct message.": MessageBox.Show("不存在此用户"); break; case "n": MessageBox.Show("用户已注册但不在线"); break; default: MessageBox.Show($"用户主机位于{recv}"); break; } }
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; var xml = ResourceLoader.XmlLoader <ServerInfoDto>("./Server.xml"); Log.Logger = new LoggerConfiguration() .Destructure.ByTransforming <IPEndPoint>(endPoint => endPoint.ToString()) .Destructure.ByTransforming <EndPoint>(endPoint => endPoint.ToString()) .WriteTo.File("GameServer.txt") .WriteTo.Console(outputTemplate: "[{Level} {SourceContext}][{AID}:{AUser}] {Message}{NewLine}{Exception}") .MinimumLevel.Debug() .CreateLogger(); Console.Title = $"GameServer .NetCore2 [{xml.Code}]{xml.Name} Client:{xml.Version}#!{xml.Serial} DB:" + xml.DataBase; ConnectionString = $"Server={xml.DBIp};port=3306;Database={xml.DataBase};user={xml.BDUser};password={xml.DBPassword};Convert Zero Datetime=True;"; SimpleModulus.LoadDecryptionKey("Dec1.dat"); SimpleModulus.LoadEncryptionKey("Enc2.dat"); 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; 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()) .RegisterRule <CIDAndPass>(MustNotBeLoggedIn) .RegisterRule <CCharacterList>(MustBeLoggedIn) .RegisterRule <CCharacterMapJoin>(MustBeLoggedIn) .RegisterRule <CCharacterMapJoin2>(MustBeLoggedIn) }; var mf = new MessageFactory[] { new AuthMessageFactory(), new GlobalMessageFactory(), new GameMessageFactory(), new CashShopMessageFactory(), new EventMessageFactory(), new QuestSystemMessageFactory(), new GuildMessageFactory(), }; server = new WZGameServer(ip, mh, mf); 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(); SubSystem.Initialize(); }catch (MySql.Data.MySqlClient.MySqlException ex) { Migrate(null, new EventArgs()); Log.Information("Server needs restart to reload all changes"); Task.Delay(10000); return; } catch (Exception ex) { Log.Error(ex, "Error on initialization"); } try { client = new CSClient(csIP, cmh, cmf, (ushort)xml.Code, server, (byte)xml.Show); }catch (Exception) { Log.Error("Connect Server Unavailable"); } Log.Information("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("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>("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>("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); } }
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); } }
/// <summary> /// Initialisiert eine neue Instanz der CardServerConnectionStateChangedEventArg-Klasse. /// </summary> /// <param name="csClient">Instanz des CardServer Clients</param> public CardServerConnectionEventArgs(CSClient csClient) { _csClient = csClient; }