public static bool ValidateEncryptionKey(string endpoint, ServerToken token) { bool valid; try { var webReq = WebRequest.Create(new Uri(endpoint)); webReq.ContentType = "application/json"; webReq.Method = "POST"; var json = JsonSerializer.Serialize(token); using (var sw = new StreamWriter(webReq.GetRequestStream())) { sw.Write(json); } var response = webReq.GetResponse(); using (var sr = new StreamReader(response.GetResponseStream())) { valid = (bool)JsonSerializer.Deserialize(sr.ReadToEnd(), typeof(bool)); } } catch (Exception e) { Game.ReportException(e); GameLog.Error("ValidateEncryptionKey failure: {e}", e); return(false); } return(valid); }
public static void Execute(object obj, ElapsedEventArgs args) { GameLog.Debug("Job starting"); try { // FIXME: make this more efficient / don't break our own conventions foreach (var connection in GlobalConnectionManifest.WorldClients) { var client = connection.Value; var connectionId = connection.Key; if (client.IsIdle()) { User user; if (Game.World.WorldData.TryGetValueByIndex(connectionId, out user)) { user.Motion(16, 120); // send snore effect } else { GameLog.WarningFormat( "Connection id {0} marked as idle but no corresponding user found...?", connectionId); } } } GameLog.Debug("Job complete"); } catch (Exception e) { Game.ReportException(e); GameLog.Error("Exception occured in job:", e); } }
public static void DeregisterClient(Client client) { ConnectedClients.TryRemove(client.ConnectionId, out Client _); GameLog.InfoFormat("Deregistering {0}", client.ConnectionId); // Send a control message to clean up after World users; Lobby and Login handle themselves if (client.ServerType == ServerTypes.World) { if (!WorldClients.TryRemove(client.ConnectionId, out Client _)) { GameLog.Error("Couldn't deregister cid {id}", client.ConnectionId); } try { if (!World.ControlMessageQueue.IsCompleted) { World.ControlMessageQueue.Add(new HybrasylControlMessage(ControlOpcodes.CleanupUser, CleanupType.ByConnectionId, client.ConnectionId)); } } catch (InvalidOperationException e) { Game.ReportException(e); if (!World.ControlMessageQueue.IsCompleted) { GameLog.ErrorFormat("Connection {id}: DeregisterClient failed", client.ConnectionId); } } } }
private TableLoader GetTableLoaderByName(string name) { TableLoader table = null; if (string.IsNullOrEmpty(name)) { GameLog.Error("ERROR!!!----TableManager:GetTableLoaderByName----name is null!!!"); return(table); } if (!_tableLoaderList.ContainsKey(name)) { GameLog.Error("ERROR!!!----TableManager:GetTableLoaderByName----TableConfig don't have table which name is {0}!!!", name); return(table); } if (_tableLoaderList.TryGetValue(name, out table)) { if (table.TableDataDict == null) { table.Load(); } } else { GameLog.Error("ERROR!!!----TableManager:GetTableLoaderByName----TableLoaderList Get Fail!!! name = {0}", name); } return(table); }
public object GetTableData(string name, int id) { if (string.IsNullOrEmpty(name) || id <= 0) { GameLog.Error("ERROR!!!----TableManager:GetTableData----param is wrong!!!"); return(null); } Dictionary <int, object> table = GetTableByName(name); if (table == null) { GameLog.Error("ERROR!!!----TableManager:GetTableData----get table failed!!! name = {0}", name); return(null); } object tableLine = null; if (table.TryGetValue(id, out tableLine)) { return(tableLine); } else { GameLog.Error("ERROR!!!----TableManager:GetTableData----Table {0} not find id = {1}!!", name, id.ToString()); } return(tableLine); }
protected override void LoadContent() { base.LoadContent(); var editorServerUri = StartupOptions.EditorServerUri; if (!string.IsNullOrWhiteSpace(editorServerUri)) { _communication = new ArcCommunication(this); var b = Uri.TryCreate(editorServerUri, UriKind.RelativeOrAbsolute, out var edServerUri); if (!b) { GameLog.Error("Invalid URI format (in editor_server_uri command line param): {0}", editorServerUri); } _communication.EditorServerUri = edServerUri; var simulatorServerPort = StartupOptions.SimulatorServerPort; _communication.Server.Start(simulatorServerPort); _communication.Client.SendLaunchedNotification(); } }
private void Handle_Completed(AssetOperationHandle obj) { TextAsset temp = _handle.AssetObject as TextAsset; if (temp != null) { try { SecurityParser sp = new SecurityParser(); sp.LoadXml(temp.text); _xml = sp.ToXml(); // 解析数据 if (_xml != null) { ParseData(); } } catch (Exception ex) { GameLog.Error($"Failed to parse xml {Location}. Exception : {ex.ToString()}"); } } // 注意:为了节省内存这里立即释放了资源 _handle.Release(); _userCallback?.Invoke(); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var equipJObj = serializer.Deserialize <Dictionary <byte, InventorySlot> >(reader); var equipment = new Inventory(Inventory.DefaultSize); for (byte i = 1; i <= equipment.Size; i++) { if (equipJObj.TryGetValue(i, out var slot)) { if (Game.World.WorldData.TryGetValue <Item>(slot.Id, out Item ItemTemplate)) { equipment[i] = new ItemObject(slot.Id, Game.GetDefaultServerGuid <World>(), new Guid(slot.Guid)) { Count = slot.Count, Durability = slot.Durability }; } else { GameLog.Error($"Inventory deserializer error: item {slot.Id} not found in index, skipping"); equipment[i] = null; } } else { equipment[i] = null; } } return(equipment); }
public void Load() { //TableConfig表已提前加载 if (_tableConfigVO.Id <= 0) { //GameLog.Error("ERROR!!!----TableLoader:Load----_tableConfigVO.Id<0"); return; } if (_dataDict != null) { GameLog.Error("ERROR!!!----TableLoader:Load----重复加载表:" + _tableName); return; } _byteData = ResourceManager.Instance.LoadTable(_tableConfigVO.ResourcePath + ".bin"); Type tableType = Type.GetType("Game.Table.Static." + _tableName + "Table"); //Type tableVOType = Type.GetType(_tableName+"VO"); string methodName = "GetRootAs{0}Table".Replace("{0}", _tableName); object obj = tableType.InvokeMember(methodName, BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public, null, null , new object[] { new ByteBuffer(_byteData) }); MethodInfo method = tableType.GetMethod("GetTableData"); _dataDict = (Dictionary <int, object>)method.Invoke(obj, null); if (_dataDict == null) { GameLog.Error("ERROR!!!----TableLoader:Load----表{0}序列化失败", _tableName); } }
public override Task <BooleanMessageReply> BeginShutdown(BeginShutdownRequest request, ServerCallContext context) { var resp = new BooleanMessageReply { Message = "An unknown error occurred", Success = false }; try { if (!World.ControlMessageQueue.IsAddingCompleted) { World.ControlMessageQueue.Add(new HybrasylControlMessage(ControlOpcodes.ShutdownServer, context.Peer, request.Delay)); resp.Message = "Shutdown request successfully submitted"; resp.Success = true; } else { resp.Message = "Control message queue closed (shutdown already in progress?)"; } } catch (Exception e) { Game.ReportException(e); GameLog.Error("GRPC: Shutdown request failed, {e}", e); } return(Task.FromResult(resp)); }
public static int Run([NotNull, ItemNotNull] string[] args, GraphicsBackend graphicsBackend, [NotNull] string loggerName = "theater-days") { GraphicsBackend = graphicsBackend; GameLog.Initialize(loggerName); GameLog.Enabled = true; var exitCode = -1; var parser = new Parser(settings => { settings.IgnoreUnknownArguments = true; }); var optionsParsingResult = parser.ParseArguments <Options>(args); #if ENABLE_GUI_CONSOLE GuiConsole.Initialize(); GuiConsole.Error.WriteLine(); #endif #if SAFE_STARTUP try { #endif if (optionsParsingResult.Tag == ParserResultType.Parsed) { var options = ((Parsed <Options>)optionsParsingResult).Value; GameLog.Enabled = options.IsDebugEnabled; using (var pluginManager = new TheaterDaysPluginManager()) { pluginManager.LoadPlugins(); var configurationStore = ConfigurationHelper.CreateConfigurationStore(pluginManager); var cultureSpecificInfo = CultureSpecificInfoHelper.CreateCultureSpecificInfo(); using (var game = new Theater(options, pluginManager, configurationStore, cultureSpecificInfo)) { game.Run(); } exitCode = 0; } } else { var helpText = CommandLine.Text.HelpText.AutoBuild(optionsParsingResult); GameLog.Info(helpText); } #if SAFE_STARTUP } catch (Exception ex) { GameLog.Error(ex.Message); GameLog.Error(ex.StackTrace); } #endif #if ENABLE_GUI_CONSOLE GuiConsole.Uninitialize(); #endif return(exitCode); }
public void Start() { try { OnEnter(); } catch (Exception ex) { GameLog.Error("procedure logic enter error.Exception:{0} StackTrace:{1}", ex.Message, ex.StackTrace); } }
public void Update() { try { OnTick(); } catch (Exception ex) { GameLog.Error("procedure logic tick error.Exception:{0} StackTrace:{1}", ex.Message, ex.StackTrace); } }
public void OnDestroy() { try { OnLeave(); } catch (Exception ex) { GameLog.Error("procedure logic leave error.Exception:{0} StackTrace:{1}", ex.Message, ex.StackTrace); } }
public void RemoveThreat(Creature threat) { if (!ThreatTableByCreature.TryGetValue(threat.Guid, out ThreatEntry entry)) { return; } ThreatTableByCreature.Remove(threat.Guid); ThreatTableByThreat.Remove(entry); GameLog.Error($"{OwnerObject.Id}: Removed threat {threat.Id}"); }
// protected callback public void Awake() { try { procedure = (T)(GameContext.procedureSrv.GetCurProcedure()); OnInit(); } catch (Exception ex) { GameLog.Error("procedure logic init error.Exception:{0} StackTrace:{1}", ex.Message, ex.StackTrace); } }
public static void HandleException(string message, Exception e) { if (!object.ReferenceEquals(UnityLogHandler.MainExecutor, null)) { UnityLogHandler.MainExecutor.RunOnMainThread(delegate { UnityLogHandler.HandleLog(message, e.StackTrace, LogType.Exception); }); } GameLog.Error(e, message); }
private void SwitchProcedure(LogicType next) { if (_CurLogicType == LogicType.None) { GameLog.Error("---------------------MainProcedure:SwitchProcedure----------_CurLogicType= LogicType.None!!!!"); return; } //GameLog.Debug("---------------------MainProcedure:SwitchProcedure----------_CurLogicType = {0}, next = {1}", _CurLogicType, next); _CurLogicType = next; }
/// <summary> /// Add a dialog option which will fire a JumpDialog when selected by a player. /// </summary> /// <param name="option">The option text</param> /// <param name="nextDialog">The JumpDialog that will be used by this option</param> public void AddOption(string option, HybrasylDialog nextDialog) { if (nextDialog.DialogType == typeof(JumpDialog)) { Options.Add(option, nextDialog); } else { GameLog.Error($"Dialog option {option}: unsupported dialog type {nextDialog.DialogType.Name}"); } }
private async void SaveToDisk(string sender, string id, string text) { try { await File.WriteAllTextAsync(Path.Join(OutputDir, $"bugreport-{sender}-{id}.txt"), text); } catch (Exception e) { GameLog.Error("BugReporter: failure to write out log: {e}, plugin disabled", e); Disabled = true; } }
public static void RunAsync(Action job) { Assert.NotNull(job, "job"); ThreadPool.QueueUserWorkItem(delegate { try { job(); } catch (Exception e) { GameLog.Error(e.Message); } }); }
/// <summary> /// Register a constructed dialog sequence with the current world object, which makes it available for use by that object. /// Dialogs must be registered before they can be used. /// </summary> /// <param name="hybrasylSequence"></param> public void RegisterSequence(HybrasylDialogSequence hybrasylSequence) { if (hybrasylSequence is null) { GameLog.Error("RegisterSequence called with null/nil value. Check Lua"); return; } if (Obj is VisibleObject && !(Obj is User)) { var vobj = Obj as VisibleObject; vobj.RegisterDialogSequence(hybrasylSequence.Sequence); } }
/// <summary> /// Create a new text dialog (a dialog that asks a player a question; the player can type in a response). /// </summary> /// <param name="displayText">The text to be displayed in the dialog</param> /// <param name="topCaption">The top caption of the text box input</param> /// <param name="bottomCaption">The bottom caption of the text box input</param> /// <param name="inputLength">The maximum length (up to 254 characters) of the text that can be typed into the dialog by the player</param> /// <param name="callback">The callback function or lua expression that will fire when this dialog is shown to a player.</param> /// <param name="handler">The function or lua expression that will handle the response once the player hits enter / hits next.</param> /// <returns>The constructed dialog</returns> public HybrasylDialog NewTextDialog(string displayText, string topCaption, string bottomCaption, int inputLength = 254, string callback = "", string handler = "") { if (string.IsNullOrEmpty(displayText)) { GameLog.Error("NewTextDialog: display text (first argument) was null"); return(null); } var dialog = new TextDialog(displayText, topCaption, bottomCaption, inputLength); dialog.SetInputHandler(handler); dialog.SetCallbackHandler(callback); return(new HybrasylDialog(dialog)); }
/// <summary> /// Register a constructed dialog sequence with the current world object, which makes it available for use by that object. /// Dialogs must be registered before they can be used. /// </summary> /// <param name="hybrasylSequence"></param> public void RegisterSequence(HybrasylDialogSequence hybrasylSequence) { if (hybrasylSequence is null || hybrasylSequence.Sequence.Dialogs.Count == 0) { GameLog.Error("RegisterSequence: sequence (first argument) was null or contained no dialogs, ignoring"); return; } if (Obj is VisibleObject && !(Obj is User)) { var vobj = Obj as VisibleObject; vobj.RegisterDialogSequence(hybrasylSequence.Sequence); } }
private static int Main([NotNull, ItemNotNull] string[] args) { BaseGame.GraphicsBackend = GraphicsBackend.Direct3D11; GameLog.Initialize("arcaea-debug"); GameLog.Enabled = true; var exitCode = -1; var parser = new Parser(settings => { settings.IgnoreUnknownArguments = true; settings.CaseInsensitiveEnumValues = true; }); var optionsParsingResult = parser.ParseArguments <Options>(args); try { if (optionsParsingResult.Tag == ParserResultType.Parsed) { var options = ((Parsed <Options>)optionsParsingResult).Value; // Enable game log if the app is launched with "--debug" switch. GameLog.Enabled = options.IsDebugEnabled; using (var pluginManager = new ArcaeaSimPluginManager()) { pluginManager.LoadPlugins(); var configurationStore = ConfigurationHelper.CreateConfigurationStore(pluginManager); var cultureSpecificInfo = CultureSpecificInfoHelper.CreateCultureSpecificInfo(); using (var game = new ArcaeaSimApplication(pluginManager, configurationStore, cultureSpecificInfo)) { game.Run(); } exitCode = 0; } } else { var helpText = CommandLine.Text.HelpText.AutoBuild(optionsParsingResult); GameLog.Info(helpText); } } catch (Exception ex) { GameLog.Error(ex.Message); GameLog.Error(ex.StackTrace); Debug.Print(ex.ToString()); } return(exitCode); }
public void Create(System.Action callback) { if (_spawnGo != null) { GameLog.Error($"Avatar is create yet : {_avatarTable.Id}"); return; } _callback = callback; // 对象池 _spawnGo = GameObjectPoolManager.Instance.Spawn(GetModelName()); _spawnGo.Completed += SpawnGo_Completed; }
public void LoadXmlConfig(List <Xml.PluginConfig> configuration) { lock (Lock) { foreach (var kvp in configuration) { if (!StoreValue(kvp.Key, kvp.Value)) { GameLog.Error("SimpleConfiguration: XML configuration processing failure, couldn't store key"); throw new ArgumentException("Configuration could not be stored"); } } } }
private Kingdom GoRebelKingdom(IEnumerable <Clan> clans) { var ruler = clans.First(); // create a new kingdom for the clan TextObject kingdomIntroText = new TextObject("{=Separatism_Kingdom_Intro_National}{RebelKingdom} was found in {Year} when {Culture} people of {Kingdom} have made a declaration of independence.", null); try { kingdomIntroText.SetTextVariable("Year", CampaignTime.Now.GetYear); kingdomIntroText.SetTextVariable("Culture", ruler.Culture.Name); kingdomIntroText.SetTextVariable("Kingdom", ruler.Kingdom.Name); } catch (Exception e) { // prevent mysterious rare crash GameLog.Error(e); return(null); } var capital = ruler.Settlements.OrderByDescending(x => x.Prosperity).First(); var kingdom = ruler.CreateKingdom(capital, kingdomIntroText); // keep policies from the old clan kingdom foreach (var policy in ruler.Kingdom.ActivePolicies) { kingdom.AddPolicy(policy); } // move all clans into the new kingdom foreach (var clan in clans) { clan.ChangeKingdom(kingdom, true); } // make relation changes for participating clans int relationChange = SeparatismConfig.Settings.RelationChangeNationalRebellionClans; if (relationChange != 0) { Queue <Clan> clanQueue = new Queue <Clan>(clans); while (clanQueue.Count > 1) { var c1 = clanQueue.Dequeue(); foreach (var c2 in clanQueue) { ChangeRelationAction.ApplyRelationChangeBetweenHeroes(c1.Leader, c2.Leader, relationChange, true); } } } return(kingdom); }
public static object Invoke(object objectThis, string name, object[] parameters) { Type type = objectThis.GetType(); string text = string.Format("{0}.{1}", type.Name, name); MethodInfo method; if (!InvokeUtils.Methods.TryGetValue(text, out method)) { try { method = type.GetMethod(name); } catch (Exception ex) { GameLog.Error("Invoke get method failed: {0}\nException: {1}", new object[] { text, ex }); } InvokeUtils.Methods.Add(text, method); } if (method != null) { try { ParameterInfo[] array = null; for (int i = 0; i < parameters.Length; i++) { if (parameters[i] == null || parameters[i].Equals(null)) { if (array == null) { array = method.GetParameters(); } parameters[i] = Convert.ChangeType(null, array[i].GetType()); } } return(method.Invoke(objectThis, parameters)); } catch (Exception ex2) { GameLog.Error("Invoke failed: {0}\nException: {1}", new object[] { text, ex2 }); } } return(null); }
private void StartLoadTable() { if (_tableLoaderList.Count <= 0) { GameLog.Error("ERROR!!!-------------TableManager:StartLoadTable----没有可以加载的表格!"); return; } if (_firstLoadFinish) { GameLog.Error("ERROR!!!-------------TableManager:StartLoadTable----重复加载初始化表格!"); return; } _loadThread = new Thread(new ParameterizedThreadStart(LoadAllTable)); _loadThread.Start(); }