/// <summary> /// 发送系统公告 /// </summary> /// <param name="token">令牌</param> /// <param name="sn">启服服务器名称</param> /// <param name="playid">玩id</param> /// <param name="sid">服务器主键id</param> /// <param name="start">开始时间</param> /// <param name="end">结束时间</param> /// <param name="space">时间间隔</param> /// <param name="content">内容</param> /// <param name="pid">平台主键id</param> /// <returns></returns> public Notice PostNotice(string token, string sn, Int64 playid, Int64 pid, Int64 sid, Int64 start, Int64 end, int space, string content) { if (!IsToken(token)) { return new Notice { result = -1, message = "令牌不存在" } } ; //验证会话 SN = sn; var notice = new Notice(); var now = DateTime.Now.Ticks; if (Convert.ToInt32(space) <= 0 || end < now || start <= 0) { return new Notice { result = -1, message = "时间设置有误" } } ; //设置连接字符串 tgm_notice.SetDbConnName(tgm_connection); var entity = new tgm_notice() { //start_time = start, //end_time = end, //time_interval = space, content = content, player_id = playid, pid = pid, sid = sid, }; entity.Save(); notice = ToEntity.ToNotice(entity); notice.result = 1; return(notice); } } }
// POST api/Message?token={token}&roleid={roleid}&role={role}&pid={pid}&sid={sid}&start={start}&end={end}&space={space}&content={content} /// <summary> 发送系统公告 </summary> /// <param name="token">令牌</param> /// <param name="sid">服务器id</param> /// <param name="start">开始时间</param> /// <param name="end">结束时间</param> /// <param name="space">时间间隔</param> /// <param name="content">内容</param> /// <param name="roleid">玩家id</param> /// <param name="role">角色权限</param> /// <param name="pid">平台id</param> /// <returns></returns> public Notice PostNotice(string token, Int32 roleid, Int32 role, Int32 pid, Int32 sid, string start, string end, int space, string content) { if (!IsToken(token)) { return new Notice { result = -1, message = "令牌不存在" } } ; //验证会话 tgm_server.SetDbConnName(tgm_connection); var server = tgm_server.FindByid(sid); if (server == null) { return new Notice() { result = -1, message = "发送服务器信息不存在" } } ; SN = server.name; var now = DateTime.Now.Ticks; var stick = string.IsNullOrEmpty(start) ? now : DateTime.Parse(start).Ticks; var etick = DateTime.Parse(end).Ticks; if (Convert.ToInt32(space) <= 0 || etick < now || stick < 0) { return new Notice { result = -1, message = "时间设置有误" } } ; //设置连接字符串 tgm_role.SetDbConnName(tgm_connection); var user = tgm_role.FindByid(Convert.ToInt32(roleid)); if (user == null) { return new Notice() { result = -1, message = "没有该操作的权限" } } ; tgm_platform.SetDbConnName(tgm_connection); var pl = tgm_platform.FindByid(Convert.ToInt32(pid)); if (role != 10000) { if (pl.id != user.pid) { return new Notice() { result = -1, message = "没有权限操作该平台信息" } } ; } tg_system_notice.SetDbConnName(db_connection); var entity = new tg_system_notice() { start_time = stick, end_time = etick, time_interval = space, content = content, base_Id = 0, level = 2, state = 0, }; entity.Save(); tgm_notice.SetDbConnName(tgm_connection); var tgmentity = new tgm_notice() { start_time = stick, end_time = etick, content = content, player_id = roleid, pid = pid, sid = sid, gameid = entity.id, }; tgmentity.Save(); var notice = ToEntity.ToNotice(tgmentity); if (stick == now) { var ip = server.ip; var port = server.port_server; //解析后调用游戏接口判断是否成功 var api = new CommandApi(ip, port, ApiCommand.公告); var state = api.NoticePush(); api.Dispose(); if (state != (int)ApiType.OK) { return new Notice() { result = -1, message = "发送公告失败!" } } ; } notice.result = 1; return(notice); }