public void Execute(ServerCore server, ClientConnection connection, string[] arguments) { try { if (arguments == null || arguments.Length == 0) { return; } var time = UtopiaTimeSpan.Parse(arguments[0]); server.Clock.SetCurrentTimeOfDay(time); server.ConnectionManager.Broadcast(new DateTimeMessage { DateTime = server.Clock.Now, TimeFactor = server.Clock.TimeFactor }); server.ChatManager.Broadcast("Time updated by " + connection.DisplayName); } catch (Exception ex) { if (ex is OverflowException || ex is FormatException) { connection.Send(new ChatMessage { IsServerMessage = true, DisplayName = "server", Message = "wrong time value, try 9:00 or 21:00" }); } else { throw; } } }
public void Execute(ServerCore server, ClientConnection connection, string[] arguments) { if (connection.SelectedNpc == null) { connection.SendChat("No npc is selected"); return; } if (arguments == null || arguments.Length != 2) { connection.SendChat("Wrong parameters"); return; } try { var time = UtopiaTimeSpan.Parse(arguments[1]); var activity = new Activity { Name = arguments[0], StartAt = time }; ServerDynamicEntity serverEntity; if (!server.AreaManager.TryFind(connection.SelectedNpc.DynamicId, out serverEntity)) { connection.SendChat("Can't find the server entity"); return; } var serverNpc = serverEntity as ServerNpc; if (serverNpc == null) { connection.SendChat("Invalid type of the server entity"); return; } var humanAi = serverNpc.GeneralAI as HumanAI; if (humanAi == null) { connection.SendChat("Invalid type of the AI"); return; } humanAi.Activities.Add(activity); serverNpc.Character.OnNeedSave(); connection.SendChat("New activity was added"); } catch (Exception x) { connection.SendChat("Error: " + x); } }
// Overrides the ConvertFrom method of TypeConverter. public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { return(UtopiaTimeSpan.Parse((string)value)); } return(base.ConvertFrom(context, culture, value)); }