private bool UpdateState(tg_system_notice notice, Int64 time) { if (time <= 1000) { notice.state = (int)NoticeStateType.OBSOLETE; } else { notice.state = (int)NoticeStateType.RUN; } notice.Update(); return(notice.state == (int)NoticeStateType.RUN); }
/// <summary> 插入公告 </summary> /// <param name="baseid">系统公告的基表id 无就填0</param> /// <param name="content">内容</param> /// <param name="statime">公告开始时间</param> /// <param name="endtime">公告结束时间</param> /// <param name="level">公告级别</param> /// <param name="interval">公告的推送间隔</param> private void InsertNotice(int baseid, string content, Int64 statime, Int64 endtime, int level, int interval) { var model = new tg_system_notice { level = level, base_Id = baseid, content = content, end_time = endtime, start_time = statime, time_interval = interval, }; model.Insert(); }
// 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); }