public async Task GetShopRoleInfo(SocketRole role) { var user = _context.User as SocketGuildUser; if (user == null) { //todo: error handle return; } try { var serverCache = ServerDataManager.GetServerDataByServerId(_context.Guild.Id); var shopRole = serverCache.GetShopRoleModel()[role.Id]; var builder = new EmbedBuilder(); builder.WithAuthor(user.Username, user.GetAvatarUrl()); builder.WithColor(255, 183, 229); builder.AddField("Role name", role.Name); builder.AddField("Role cost", shopRole.GetRoleCost()); builder.AddField("Required level", shopRole.GetRequiredLevel()); await _context.Channel.SendMessageAsync("", false, builder.Build()); } catch (Exception) { await _context.Channel.SendMessageAsync("This role is not a shop role"); } }
static void Main(string[] args) { NetworkDebuger.IsUnity = false; NetworkDebuger.EnableLog = true; NetworkDebuger.EnableSave = true; NetworkDebuger.DeleteFiles(); NetworkDebuger.Log(nameof(NetworkDebuger) + " Init"); // SqlManager.Init(); ServerDataManager.Init(); new AsyncIOCPServer(IP, portTCP, 30000); UdpServer.Instance.Init(IP, portUDP); while (true) { string msg = Console.ReadLine(); if (msg.Contains("quit"))//quit-1-1 { string[] sp = msg.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries); int roomID = int.Parse(sp[1]); int unique = int.Parse(sp[2]); bool isQuit = ServerDataManager.instance.allRoom.RoomList[roomID].Quit(unique); Console.WriteLine("踢房间->" + roomID + " 站位->" + unique + " 结果->" + isQuit); } if (msg == "test") { } } }
public void MessageRecieved(SocketCommandContext context) { var serverData = ServerDataManager.GetServerDataByServerId(context.Guild.Id); UserDataModel currentUserData; try { currentUserData = serverData.GetUserDataModel()[context.User.Id]; } catch (Exception) { currentUserData = new UserDataModel(context.User.Id, context.User.Username); currentUserData.LastUserCurrencyUpdateTimeBinary = 0; serverData.SetUserData(context.User.Id, currentUserData); } var random = new Random(); var randomNumber = random.Next(25, 60); var fiveMinutesAsBinary = new DateTime().AddMinutes(5).ToBinary(); var allowedUpdateTimeAsBinary = currentUserData.LastUserCurrencyUpdateTimeBinary + fiveMinutesAsBinary; var currentTimeAsBinary = DateTime.UtcNow.ToBinary(); if (allowedUpdateTimeAsBinary <= currentTimeAsBinary) { currentUserData.AddUserCurrency(randomNumber); currentUserData.SetLastCurrencyUpdateAsBinary(currentTimeAsBinary); } }
public ActionResult GetDbServerList() { string message = null; List <EM_ServerConnect> data = new List <EM_ServerConnect>(); try { ServerDataManager dataAccess = new ServerDataManager(new ServerConnectVariable(), DBServerProvider.MS_SQL); dataAccess.GetDatabaseServerList(out data, out message); //create dummy data //message = Message.Message_OK; data.Add(new EM_ServerConnect { Id = 0, ConnectionName = "New Connect", DatabaseName = "db name", TableName = "table Name", ServerUserName = "******", ServerHostNameIP = "130", }); } catch (Exception ex) { message = ex.Message; } return(Json(new { message, data }, JsonRequestBehavior.AllowGet)); }
public static void Init() { if (instance == null) { instance = new ServerDataManager(); } }
public async Task GetAllShopRoles() { var user = _context.User as SocketGuildUser; var serverData = ServerDataManager.GetServerDataByServerId(_context.Guild.Id); if (user == null) { return; } var shopRoles = serverData.GetShopRoleModel(); var builder = new EmbedBuilder(); builder.WithAuthor(user.Username, user.GetAvatarUrl()); builder.WithColor(255, 183, 229); var embedField = new EmbedFieldBuilder(); embedField.WithName("Shop Roles"); //todo: add page system foreach (var shopRole in shopRoles) { embedField.Value += _context.Guild.GetRole(shopRole.Value.GetRoleId()).Mention + "\n"; } builder.AddField(embedField); await _context.Channel.SendMessageAsync("", false, builder.Build()); }
public void PersistAppData() { //serialize application data ServerDataManager.SaveData(Servers.ToList()); //don't persist backup data until we have it updated with file watcher //BackupDataManager.SaveData(Backups.ToList()); DataManager.SaveSettings(); }
private void InitializeAppData() { //deserialize application data Servers = new BetterObservableCollection <Server>(ServerDataManager.LoadData()); Backups = new BetterObservableCollection <Backup>(BackupDataManager.LoadData()); //associate servers/backups with one another based on ID's AssociateCollections(); //add event listeners to save each time server collection changes. Servers.CollectionChanged += PersistantData_Changed; Backups.CollectionChanged += PersistantData_Changed; }
void Update() { if (DataManager == null) { return; } _DataManager = DataManager.GetComponent <ServerDataManager>(); if (_DataManager == null) { return; } if (_DataManager.isReaderClosed()) { return; } _DepthData = _DataManager.GetChosenDepthData(); if (_DepthData == null) { return; } _ColorData = _DataManager.GetChosenColorData(); if (_ColorData == null) { return; } // 1) Send general data //CustomMessagesPointCloud.Instance.SendGeneralData(_DataManager.DSPWidth, _DataManager.DSPHeight); CustomMessagesPointCloud.Instance.SendDepthData(_DepthData); /* * Debug.Log("DSPWidth: " + _DataManager.DSPWidth); * Debug.Log("DSPHeight: " + _DataManager.DSPHeight);*/ //CustomMessagesPointCloud.Instance.SendColorData(_ColorData); // 2) Send depth data 1 // 3) Send depth data 2 // 4) Send R data // 5) Send G data // 6) Send B data }
public async Task ShowBalance(SocketCommandContext context) { var serverData = ServerDataManager.GetServerDataByServerId(context.Guild.Id); var userData = serverData.GetUserDataModel()[context.User.Id]; var builder = new EmbedBuilder(); builder.WithAuthor(context.User.Username, context.User.GetAvatarUrl()); builder.WithTitle("Balance"); builder.WithColor(255, 183, 229); builder.WithDescription("You have a balance of **¥" + userData.GetUserCurrency() + "**"); await context.Channel.SendMessageAsync("", false, builder.Build()); }
private void OnFileChanged(object sender, System.IO.FileSystemEventArgs e) { if (e.FullPath == DataManager.ServersFilePath) { //update servers ModalMessage("resettings backup timers"); List <Server> servers = ServerDataManager.LoadData(); InitBackupTimers(servers); } else if (e.FullPath == DataManager.BackupsFilePath) { //update backups? probably not necessary ModalMessage("updating backups?"); } }
void Update() { if (DataManager == null) { return; } _DataManager = DataManager.GetComponent <ServerDataManager>(); if (_DataManager == null) { return; } gameObject.GetComponent <Renderer>().material.mainTexture = _DataManager.GetChosenColorTexture(); }
/// <summary> /// Auto unmutes the a user if the mute timer has expired. /// </summary> /// <param name="guild">Gives the current guild that is being checked.</param> public async Task AutoUnmute(IGuild guild) { var serverCache = ServerDataManager.GetServerDataByServerId(guild.Id); var mutedUsersInfo = serverCache.GetUserDataModel().Values.Where(x => x.MuteData != null).ToList(); if (mutedUsersInfo.Count <= 0) { return; } var muteRole = serverCache.GetServerSettingsModel()["mute_role"]; //Loops through every muted user foreach (var mutedUser in mutedUsersInfo) { var muteData = mutedUser.GetMuteData(); //Checks if the mute timer has already expired if (DateTime.Now.ToBinary() >= muteData.GetUnmuteTimeAsBinary()) { var muteRoleId = Convert.ToUInt64(muteRole.Value); var discordUser = await guild.GetUserAsync(mutedUser.GetUserId()) as SocketGuildUser; //Checks if the user is still in the server if (discordUser != null) { //Checks if the user has the muted role if (discordUser.Roles.Any(role => role.Id == muteRoleId)) { await discordUser.RemoveRoleAsync(guild.GetRole(muteRoleId)); //Removes the muted state from the users cache mutedUser.SetMuteData(null); } else //User no longer has the muted role { //Removes the muted state from the users database entry mutedUser.SetMuteData(null); } } else //User has left the server { //Entirely removes the users database entry since they left the server and didnt join back even though the timer expired //todo : remove entry } } } }
protected override void OnStart(string[] args) { System.Diagnostics.Debugger.Launch(); DataManager.InitializeSettings(); //init settings in case the service runs before the desktop app //load in current servers and backups List <Server> servers = ServerDataManager.LoadData(); List <Backup> backups = BackupDataManager.LoadData(); //Set up file watcher InitFileWatcher(); //set up timers based on servers InitBackupTimers(servers); }
public ActionResult GetTemplateData() { List <MailTemplate> getTemplateList = new List <MailTemplate>(); string message = null; ServerDataManager dataAccess = new ServerDataManager(new ServerConnectVariable(), DBServerProvider.MS_SQL); dataAccess.GetTemplateList(out getTemplateList, out message); //create dummy data message = Message.Message_OK; getTemplateList.Add(new MailTemplate { Id = 1, TemplateName = "test", TemplateFilePath = "/mail/ashdkj" }); return(Json(new { data = getTemplateList, message = message }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Unmutes a given user. /// </summary> /// <param name="context">Gives the context needed to execute the command.</param> /// <param name="unmuteUser">Gives the user that needs to be unmuted.</param> public async Task Unmute(SocketCommandContext context, SocketGuildUser unmuteUser) { var serverCache = ServerDataManager.GetServerDataByServerId(context.Guild.Id); var user = context.User as SocketGuildUser; if (user == null) { //todo: error handle return; } if (user.GuildPermissions.MuteMembers) { var serverSettingsModel = serverCache.GetServerSettingsModel()["mute_role"]; var roleId = Convert.ToUInt64(serverSettingsModel.GetValue()); if (unmuteUser.Roles.Any(role => role.Id == roleId)) { await unmuteUser.RemoveRoleAsync(context.Guild.GetRole(roleId)); var builder = new EmbedBuilder(); builder.WithAuthor(unmuteUser.Username, unmuteUser.GetAvatarUrl()); builder.WithTitle("User has been unmuted!"); builder.WithColor(255, 183, 229); builder.AddField("Unmuted User", unmuteUser.Username, true); builder.AddField("Unmuted User ID", unmuteUser.Id, true); //Removes the muted state from the users cache var mutedUser = serverCache.GetUserDataModel()[unmuteUser.Id]; mutedUser.SetMuteData(null); await context.Channel.SendMessageAsync("", false, builder.Build()); } else { await context.Channel.SendMessageAsync("This user is not muted!"); } } else { await context.Channel.SendMessageAsync("You do not have the permissions to mute a user!"); } }
public ActionResult SaveEmailTemplate(FormCollection form) { MailTemplate getMailTemplate; string message = null; try { var path = Path.Combine(Server.MapPath("~/MailTemplate/")); string TemplateName = form["TemplateName"].ToString(); string Description = form["TemplateDescription"].ToString(); MailTemplate saveMailData = new MailTemplate() { TemplateName = TemplateName, Description = Description, TemplateFilePath = path + TemplateName }; //save data ServerDataManager dataAccess = new ServerDataManager(new ServerConnectVariable(), DBServerProvider.MS_SQL); dataAccess.SaveTemplateData(ref saveMailData, out getMailTemplate, out message); if (Request.Files.Count > 0 && message == Message.Message_OK) { var file = Request.Files[0]; if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); path = Path.Combine(Server.MapPath("~/MailTemplate/"), fileName); file.SaveAs(path); } } } catch (Exception) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json("Upload failed")); } return(Json(new { data = getMailTemplate, message = message }, JsonRequestBehavior.AllowGet)); }
public ActionResult GetGroupList() { List <Group> getGroupList = new List <Group>(); string message = null; ServerDataManager dataAccess = new ServerDataManager(new ServerConnectVariable(), DBServerProvider.MS_SQL); dataAccess.GetGroupList(out getGroupList, out message); //create dummy data //message = Message.Message_OK; //getGroupList.Add(new Group //{ // Id=0, // ServerConnectId=1, // ConditionQuery="", // Description="test", // GroupName="test group", // Size=10 //}); return(Json(new { data = getGroupList, message = message }, JsonRequestBehavior.AllowGet)); }
void Start() { _DataManager = GetComponent <ServerDataManager>(); if (_DataManager == null) { return; } if (_DataManager.GetDownsampleSize() == 1) { return; } width = _DataManager.DSPWidth; height = _DataManager.DSPHeight; // create a fixed size mesh // mesh vertex position/color will be updated every frame _Mesh = new Mesh(); GetComponent <MeshFilter>().mesh = _Mesh; CreateMesh(width, height); }
public ActionResult GetProjectList() { List <Project> getProjectList = new List <Project>(); string message = null; ServerDataManager dataAccess = new ServerDataManager(new ServerConnectVariable(), DBServerProvider.MS_SQL); dataAccess.GetProjectList(out getProjectList, out message); //create dummy data message = Message.Message_OK; getProjectList.Add(new Project { Id = 0, ProjectName = "test", Status = true, ProjectTemplatePath = "path", StartTime = DateTime.Today, TimeInterval = 12, IntervalOption = "Days", ExpiredTime = DateTime.Today.AddDays(30) }); return(Json(new { data = getProjectList, message = message }, JsonRequestBehavior.AllowGet)); }
public async Task AddShopRole(SocketRole role, int cost, int requiredLevel) { var user = _context.User as SocketGuildUser; if (user == null) { //todo: error handle return; } if (user.GuildPermissions.Administrator) { var serverCache = ServerDataManager.GetServerDataByServerId(_context.Guild.Id); var shopRole = new ShopRoleModel(role.Id, role.Name, cost, requiredLevel); serverCache.AddShopRole(role.Id, shopRole); var builder = new EmbedBuilder(); builder.WithTitle("Added shop role!"); builder.WithAuthor(user.Username, user.GetAvatarUrl()); builder.WithColor(255, 183, 229); builder.AddField("Role id", role.Id); builder.AddField("Role name", role.Name); builder.AddField("Role cost", cost); if (requiredLevel > 0) { builder.AddField("Required level", requiredLevel); } await _context.Channel.SendMessageAsync("", false, builder.Build()); } else { await _context.Channel.SendMessageAsync("Only admins can add shop roles!"); } }
void Update() { if (DataManager == null) { return; } _DataManager = DataManager.GetComponent <ServerDataManager>(); if (_DataManager == null) { return; } _DepthData = _DataManager.GetChosenDepthData(); if (_DepthData == null) { return; } _ColorData = _DataManager.GetChosenColorData(); if (_ColorData == null) { return; } if (firstPass) // If first time transmitting, send general info { CustomMessagesPointCloud.Instance.SendGeneralData(_DataManager.ClipWidth, _DataManager.ClipHeight); firstPass = false; } else // Else just send depth & RGB each frame { CustomMessagesPointCloud.Instance.SendDepthData(_DepthData); CustomMessagesPointCloud.Instance.SendColorData(_ColorData); } }
void Update() { _DataManager = DataManager.GetComponent <ServerDataManager>(); if (_DataManager == null) { return; } if (_DataManager.GetDownsampleSize() == 1) { return; } if (_Mesh == null) { width = _DataManager.DSPWidth; height = _DataManager.DSPHeight; _Mesh = new Mesh(); GetComponent <MeshFilter>().mesh = _Mesh; CreateMesh(width, height); } _DepthData = _DataManager.GetSavedDepthData(); if (_DepthData == null) { return; } _ColorData = _DataManager.GetSavedColorData(); if (_ColorData == null) { return; } RefreshMesh(width, height); }
/// <summary> /// Sets the muted role in the database. /// </summary> /// <param name="context">Gives the context needed to execute the command.</param> /// <param name="role">Gives a discord role.</param> public async Task SetMuteRole(SocketCommandContext context, SocketRole role) { var serverCache = ServerDataManager.GetServerDataByServerId(context.Guild.Id); var user = context.User as SocketGuildUser; if (user == null) { //todo: error handle return; } if (user.GuildPermissions.Administrator) { var roleName = new Dictionary <string, string> { { "role_name", role.Name } }; var serverSettings = new ServerSettingsModel("mute_role", Convert.ToInt64(role.Id), roleName); serverCache.AddServerSettings(serverSettings.Id, serverSettings); } else { await context.Channel.SendMessageAsync("Only administrators are allowed to set a mute role!"); } }
/// <summary> /// Mutes a user for a set time period. /// </summary> /// <param name="context">Gives the needed context to execute the command.</param> /// <param name="mentionedUser">Gives the user that needs to be muted.</param> /// <param name="mutePeriod">Gives the time period of the mute.</param> /// <param name="reason">Gives the reason of why the user was muted.</param> public async Task AddMute(SocketCommandContext context, SocketGuildUser mentionedUser, string mutePeriod, string reason) { var serverCache = ServerDataManager.GetServerDataByServerId(context.Guild.Id); var user = context.User as SocketGuildUser; if (user == null) { //todo: error handle return; } if (user.GuildPermissions.MuteMembers) { try { var serverSettings = serverCache.GetServerSettingsModel()["mute_role"]; var logHandler = new AdminLogHandler(); //Adds an entry in the logs await logHandler.AddLogAsync( context.Guild.Id.ToString(), Convert.ToInt64(mentionedUser.Id), mentionedUser.Username, "Mute", reason); //Gives the role to the user to mute them. await mentionedUser.AddRoleAsync( context.Guild.GetRole(Convert.ToUInt64(serverSettings.Value))); var timeInt = mutePeriod.Replace(mutePeriod.Last(), ' '); if (!int.TryParse(timeInt, out var result)) { await context.Channel.SendMessageAsync("Given time was false! Usage: !Mute user 12D reason"); return; } var muteExpireTime = DateTime.Now; switch (mutePeriod.Last()) { case 's': muteExpireTime = muteExpireTime.AddSeconds(result); break; case 'm': muteExpireTime = muteExpireTime.AddMinutes(result); break; case 'h': muteExpireTime = muteExpireTime.AddHours(result); break; case 'd': muteExpireTime = muteExpireTime.AddDays(result); break; default: await context.Channel.SendMessageAsync("Only seconds, minutes, hours or days are allowed!"); return; } var muteData = new MuteDataModel(true, mutePeriod, muteExpireTime.ToBinary()); var userData = new UserDataModel(mentionedUser.Id, mentionedUser.Username); userData.SetMuteData(muteData); //Gives the user a muted state in the database serverCache.SetUserData(Convert.ToUInt64(userData.UserId), userData); var builder = new EmbedBuilder(); builder.WithAuthor(user.Username, user.GetAvatarUrl()); builder.WithColor(255, 183, 229); builder.WithCurrentTimestamp(); builder.WithTitle("A user has been muted!"); builder.AddField("Muted User", mentionedUser.Username, true); builder.AddField("Muted User ID", mentionedUser.Id, true); builder.AddField("Reason", reason); await context.Channel.SendMessageAsync("", false, builder.Build()); } catch //Cache of ServerSettings did not contain a role to mute members { var guildRoles = context.Guild.Roles.ToList(); //Checks if the server already contains a mute role var existingMuteRole = guildRoles.Find(role => role.Name == "muted"); if (existingMuteRole != null && user.GuildPermissions.Administrator) { //Adds the role to the server settings and reruns the command await SetMuteRole(context, existingMuteRole); await AddMute(context, mentionedUser, mutePeriod, reason); } else //Server did not contain a mute role { await context.Channel.SendMessageAsync( "Could not mute the user. Please ask a administrator to set the mute role using !setmuterole @role"); } } } else { await context.Channel.SendMessageAsync("You are not allowed to mute a user!"); } }
public async Task BuyItem(SocketRole role) { var user = _context.User as SocketGuildUser; if (user == null) { //todo: error handle return; } try { var serverData = ServerDataManager.GetServerDataByServerId(_context.Guild.Id); var shopRole = serverData.GetShopRoleModel()[role.Id]; var currentUserData = serverData.GetUserDataModel()[user.Id]; if (user.Roles.Any(x => x.Id == shopRole.GetRoleId())) { if (currentUserData.UserLevel >= shopRole.RequiredLevel) { if (currentUserData.UserCurrency >= shopRole.RoleCost) { currentUserData.SubtractUserCurrency(shopRole.RoleCost); await user.AddRoleAsync(_context.Guild.GetRole(shopRole.GetRoleId())); var builder = new EmbedBuilder(); builder.WithTitle("Bought shop role!"); builder.WithAuthor(user.Username, user.GetAvatarUrl()); builder.WithColor(0, 255, 0); builder.AddField("Role name", role.Name); builder.AddField("Role cost", shopRole.GetRoleCost()); builder.AddField("New balance", currentUserData.GetUserCurrency()); await _context.Channel.SendMessageAsync("", false, builder.Build()); } else { var builder = new EmbedBuilder(); builder.WithAuthor(user.Username, user.GetAvatarUrl()); builder.WithColor(255, 0, 0); builder.WithTitle("Insufficient funds!"); builder.AddField("Role cost", shopRole.GetRoleCost()); builder.AddField("Your funds", currentUserData.GetUserCurrency()); builder.AddField("Funds needed", shopRole.GetRoleCost() - currentUserData.GetUserCurrency()); await _context.Channel.SendMessageAsync("", false, builder.Build()); } } else { var builder = new EmbedBuilder(); builder.WithAuthor(user.Username, user.GetAvatarUrl()); builder.WithColor(255, 0, 0); builder.WithTitle("Your level is too low!"); builder.AddField("Role required level", shopRole.GetRequiredLevel()); builder.AddField("Your level", currentUserData.GetUserLevel()); builder.AddField("Levels needed", shopRole.GetRequiredLevel() - currentUserData.GetUserLevel()); await _context.Channel.SendMessageAsync("", false, builder.Build()); } } else { await _context.Channel.SendMessageAsync("You already own this role!"); } } catch (Exception) { await _context.Channel.SendMessageAsync("This role is not a shop role"); } }