using System; using System.Collections.Generic; using System.Linq; using Sog; using LitJson; using SimpleHttpServer; using MySql.Data.MySqlClient; using ProtoCSStruct; namespace Operation { public class lamp { public long sendTime; public string triggerTime; public string content; } [MenuMapping(refc = typeof(SendEmail))] public class SysNoticeLamp { public static List lampCache = new List(); [RequestMapping("跑马灯",PermissionCode.NOTIFIC_SELECT_LIMP,true)] public static int OnSelectNoticeLampHttpReq(string httpApiCmd, JsonData jsonData, HttpResponse rsp, HttpRequest request, HttpQueryParams query, uint httpContextId) { TraceLog.Trace("SysNoticeLamp.OnSelectNoticeLampHttpReq url {0} ,param count {1} ,httpContextId {2}", request.Url, query.Count, httpContextId); string id = query.GetValue("id") ?? ""; if (id.Toint32(0) < 0) { jsonData["ret"] = 7; jsonData["msg"] = "查询id错误!"; return 7; } TraceLog.Trace("SysNoticeLamp.OnSelectNoticeLampHttpReq id {0}", id); RepeatedFixedStructString128_10 data = new RepeatedFixedStructString128_10(); data.Add(id); HttpApiRootHandler.FillHttpApiDbReq2MessageTaskDistributor(httpApiCmd, httpContextId, ref data); rsp.IsWaitFor = true; return 0; } public static int DoSelectNoticeLamp(string httpApiCmd, SSHttpApiDbReq req, DBOperator dbOperator) { TraceLog.Trace("SysNoticeLamp.DoSelectNoticeLamp HttpContextId {0}", req.HttpContextId); HttpRequestInfo m_request = null; LitJson.JsonData builder = new LitJson.JsonData(); try { var httpContextId = req.HttpContextId; m_request = OperationServer.m_httpService.m_requestList.Find(f => f.Http.id == httpContextId); if (req.Data.Count < 1) { TraceLog.Error("SysNoticeLamp.DoSelectNoticeLamp param error"); builder["ret"] = 2; builder["msg"] = "参数错误"; } else dbOperator.DBSelectNoticeLamp(req.Data[0].ToString(), builder); } catch (Exception ex) { TraceLog.Error("SysNoticeLamp.DoSelectNoticeLamp Error Msg {0}", ex.Message); } finally { if (m_request != null) { m_request.Http.httpResponse.ContentAsUTF8 = builder.ToJson(); m_request.ProcessEnd = true; } } TraceLog.Trace("SysNoticeLamp.DoSelectNoticeLamp success httpContextId {0}", req.HttpContextId); return 0; } [RequestMapping("发送跑马灯",PermissionCode.NOTIFIC_SEND_LIMP, toLog: true)] public static int OnSendNoticeLampHttpReq(string httpApiCmd, JsonData jsonData, HttpResponse rsp, HttpRequest request, HttpQueryParams query, uint httpContextId) { TraceLog.Trace("SysNoticeLamp.OnSendNoticeLampHttpReq url {0} ,param count {1} ,httpContextId {2}", request.Url, query.Count, httpContextId); string strTriggerTime = query.GetValue("triggerTime"); int showCount, cycleTimeType, showInterval; string content = query.GetValue("content"); string Realmliststr = query.GetValue("realmlist"); long nowSec = OperationServerUtils.GetTimeSecond(); if (lampCache.Count > 0) { // 一分钟以内只能一条 if (nowSec < lampCache.Last().sendTime + 60) { TraceLog.Error("SysNoticeLamp.OnSendNoticeLampHttpReq send too frequence"); jsonData["ret"] = -1; jsonData["msg"] = "send too fast"; return -1; } if (lampCache.Last().triggerTime == strTriggerTime && lampCache.Last().content == content) { TraceLog.Error("SysNoticeLamp.OnSendNoticeLampHttpReq send same last one"); jsonData["ret"] = -2; jsonData["msg"] = "send same"; return -2; } } if (int.TryParse(query.GetValue("cycleTimeType"), out cycleTimeType) == false) { TraceLog.Error("SysNoticeLamp.OnSendNoticeLampHttpReq cycleTimeType {0} error", query.GetValue("cycleTimeType")); jsonData["ret"] = -3; jsonData["msg"] = "cycleTimeType value invalid"; return -3; } if (cycleTimeType < 1 || cycleTimeType > 3) { TraceLog.Error("SysNoticeLamp.SysNoticeLamp cycleTimeType int {0} error", cycleTimeType); jsonData["ret"] = -4; jsonData["msg"] = "cycleTimeType value invalid"; return -4; } if (int.TryParse(query.GetValue("showInterval"), out showInterval) == false) { TraceLog.Error("SysNoticeLamp.SysNoticeLamp showInterval {0} error", query.GetValue("showInterval")); jsonData["ret"] = -5; jsonData["msg"] = "showInterval value invalid"; return -5; } if (int.TryParse(query.GetValue("showCount"), out showCount) == false) { TraceLog.Error("SysNoticeLamp.SysNoticeLamp showCount {0} error", query.GetValue("showCount")); jsonData["ret"] = -6; jsonData["msg"] = "showCount value invalid"; return -4; } if (content == "" || strTriggerTime == "") { TraceLog.Error("SysNoticeLamp.SysNoticeLamp content {0} or triggerTime {1} error", content, strTriggerTime); jsonData["ret"] = -7; jsonData["msg"] = "content value invalid"; return -7; } if (showCount <= 0) { showCount = 1; } if (showInterval <= 0) { showInterval = 30; } long triggerTime; if (cycleTimeType == 1 || cycleTimeType == 2) { triggerTime = ConfigStringTimeParse.ParseConfigTime(strTriggerTime); if (triggerTime == 0) { TraceLog.Error("SysNoticeLamp.SysNoticeLamp triggerTime {0}", strTriggerTime); jsonData["ret"] = -9; jsonData["msg"] = "triggerTime value invalid"; return -9; } } //每周,格式是1,2,3|12:00:00 if (cycleTimeType == 3) { string[] split = strTriggerTime.Split('|'); if (split.Length != 2 || split[0].Split(',').Length != 0 || 0 == ConfigStringTimeParse.ParseConfigTime(split[1])) { jsonData["ret"] = -10; jsonData["msg"] = "strTriggerTime value invalid"; return -10; } } TraceLog.Trace("SysNoticeLamp.OnSendNoticeLampHttpReq strTriggerTime {0} content {1} showCount {2} cycleTimeType {3} showInterval {4} Realmliststr {5}", strTriggerTime, content, showCount, cycleTimeType, showInterval, Realmliststr); RepeatedFixedStructString128_10 data = new RepeatedFixedStructString128_10(); data.Add(strTriggerTime); data.Add(content); data.Add(showCount.ToString()); data.Add(cycleTimeType.ToString()); data.Add(showInterval.ToString()); data.Add(Realmliststr); HttpApiRootHandler.FillHttpApiDbReq2MessageTaskDistributor(httpApiCmd, httpContextId, ref data); rsp.IsWaitFor = true; return 0; } public static int DoSendNoticeLamp(string httpApiCmd, SSHttpApiDbReq req, DBOperator dbOperator) { TraceLog.Trace("SysNoticeLamp.DoSelectNoticeLamp HttpContextId {0}", req.HttpContextId); HttpRequestInfo m_request = null; LitJson.JsonData builder = new LitJson.JsonData(); try { var httpContextId = req.HttpContextId; m_request = OperationServer.m_httpService.m_requestList.Find(f => f.Http.id == httpContextId); if (req.Data.Count < 6) { TraceLog.Error("SysNoticeLamp.DoSelectNoticeLamp param error"); builder["ret"] = 2; builder["msg"] = "参数错误"; } else { dbOperator.DBSendNoticeLamp(req.Data[0].ToString(), req.Data[1].ToString(), int.Parse(req.Data[2].ToString()), int.Parse(req.Data[3].ToString()), int.Parse(req.Data[4].ToString()), req.Data[5].ToString(), builder); lampCache.Add(new lamp { sendTime = OperationServerUtils.GetTimeSecond(), content = req.Data[1].ToString(), triggerTime = req.Data[0].ToString() }); SendSysNoticeLampReq(req.Data[0].ToString(), req.Data[1].ToString(), int.Parse(req.Data[2].ToString()), int.Parse(req.Data[3].ToString()), int.Parse(req.Data[4].ToString()), req.Data[5].ToString()); } } catch (Exception ex) { TraceLog.Error("SysNoticeLamp.DoSelectNoticeLamp Error Msg {0}", ex.Message); } finally { if (m_request != null) { m_request.Http.httpResponse.ContentAsUTF8 = builder.ToJson(); m_request.ProcessEnd = true; } } TraceLog.Trace("SysNoticeLamp.DoSelectNoticeLamp success httpContextId {0}", req.HttpContextId); return 0; } public static int SendSysNoticeLampReq(string strTriggerTime, string content, int showCount, int cycleTimeType, int showInterval, string Realmliststr) { SSSysNoticeLampReq req = new SSSysNoticeLampReq(); req.TriggerTime.SetString(strTriggerTime); req.ShowCount = showCount; req.ShowInterval = showInterval; req.Content.SetString(content); req.CycleTimeType = cycleTimeType; OperationServerUtils.SendToWorld((int)SSGameMsgID.SysNoticeLampReq, ref req, 0, 0, Realmliststr); return 0; } } }