You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

653 lines
25 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Operation;
using Sog;
using LitJson;
using SimpleHttpServer;
using MySql.Data.MySqlClient;
using System.IO;
using System.Drawing;
using ProtoCSStruct;
namespace Operation
{
public enum SSNoticeType
{
ChatServer = 0,
VersionServer = 1
}
public class NoticeLanguageContent
{
public int noticeId ;
public string startTime;
public string endTime;
public int state;
public string jump;
public string jumpParam;
public string popUp;
public int sort;
public string link;
public string realmlist;
public string triggertype;
public string startTimeDay;
public string startTimefine;
public int giftbagcustoms;
public string endTimeDay;
public string endTimefine;
public string dungeonid;
public string Intervaldays;
public string isshowtimetext;
public int aotupop;
public int type;
public int popType;
public List<string> textParamList;
public List<LanguageContent> contentList;
public string timeParamStr;
public List<string> areaNameList;
public string customRealmStr;
public int pageType;
}
public class LanguageContent
{
public int id; // 新增时没有
public string language;
public string content;
public string title;
public string icon;
public string pic;
}
public class UpdateNotice
{
[RequestMapping("撤回公告",PermissionCode.BAN_NOTICE, toLog: true)]
public static int OnBanNoticeHttpReq(string httpApiCmd, JsonData Jsondata, HttpResponse rsp, HttpRequest request, HttpQueryParams query, uint httpContextId)
{
var noticeId = query.GetValue("noticeId").Toint32(0);
var state = query.GetValue("state").Toint32(0);
if (noticeId <= 0)
{
Jsondata["ret"] = -1;
Jsondata["msg"] = "noticeId 错误!";
return -1;
}
RepeatedFixedStructString128_10 data = new RepeatedFixedStructString128_10();
data.Add(noticeId.ToString());
data.Add(state.ToString());
HttpApiRootHandler.FillHttpApiDbReq2MessageTaskDistributor(httpApiCmd, httpContextId, ref data);
rsp.IsWaitFor = true;
TraceLog.Trace("UpdateNotice.OnBanNoticeHttpReq id {0}", noticeId);
return 0;
}
public static int DoBanNotice(string httpApiCmd, SSHttpApiDbReq req, DBOperator dbOperator)
{
TraceLog.Trace("UpdateNotice.DoBanNotice HttpContextId {0}", req.HttpContextId);
HttpRequestInfo m_request = null;
try
{
var httpContextId = req.HttpContextId;
m_request = OperationServer.m_httpService.m_requestList.Find(f => f.Http.id == httpContextId);
LitJson.JsonData builder = new LitJson.JsonData();
if (req.Data.Count < 2)
{
TraceLog.Error("UpdateNotice.DoBanNotice : id == 0");
builder["ret"] = 2;
builder["msg"] = "参数Id错误";
}
else
{
dbOperator.BanNotice(int.Parse(req.Data[0].ToString()), int.Parse(req.Data[1].ToString()), builder);
}
m_request.Http.httpResponse.ContentAsUTF8 = builder.ToJson();
}
catch (Exception ex)
{
TraceLog.Error("UpdateNotice.DoBanNotice Error Msg {0}", ex.Message);
}
finally
{
if (m_request != null)
{
m_request.ProcessEnd = true;
}
}
TraceLog.Trace("UpdateNotice.DoBanNotice success httpContextId {0}", req.HttpContextId);
return 0;
}
[RequestMapping("更新公告",PermissionCode.UPDATE_NOTICE, toLog: true)]
public static int OnUpdateNoticeHttpReq(string httpApiCmd, JsonData Jsondata, HttpResponse rsp, HttpRequest request, HttpQueryParams query, uint httpContextId)
{
TraceLog.Trace("UpdateNotice.OnUpdateNoticeHttpReq url {0} ,param count {1} ,httpContextId {2}", request.Url, query.Count, httpContextId);
RepeatedFixedStructString128_10 data = new RepeatedFixedStructString128_10();
try
{
NoticeLanguageContent languageContent = request.Content.ToJson<NoticeLanguageContent>();
// 新增时noticeId判断
if (languageContent.contentList.Count > 0 && languageContent.contentList[0].id == 0)
{
int noticeId = languageContent.noticeId;
if (noticeId > 0)
{
data.Add(noticeId.ToString());
}
else
{
Jsondata["ret"] = 5;
Jsondata["msg"] = "参数错误";
return 5;
}
}
HttpApiRootHandler.FillHttpApiDbReq2MessageTaskDistributor(httpApiCmd, httpContextId, ref data);
rsp.IsWaitFor = true;
}
catch (Exception ex)
{
Jsondata["ret"] = 2;
Jsondata["msg"] = "操作失败";
TraceLog.Error("UpdateNotice.OnUpdateNoticeHttpReq error:{0}!", ex.Message);
}
return 0;
}
public static int DoUpdateNotice(string httpApiCmd, SSHttpApiDbReq req, DBOperator dbOperator)
{
TraceLog.Trace("UpdateNotice.DoUpdateNotice 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);
NoticeLanguageContent languageContent = m_request.Http.httpRequest.Content.ToJson<NoticeLanguageContent>();
bool bret = true;
if (req.Data.Count > 0)
{
bret = dbOperator.DBSelectNotice(int.Parse(req.Data[0].ToString()), builder);
}
if (bret)
DoUpdateNoticeLanguageContent(languageContent, builder, dbOperator);
}
catch (Exception ex)
{
TraceLog.Error("UpdateNotice.DoUpdateNotice Error Msg {0}", ex.Message);
}
finally
{
if (m_request != null)
{
m_request.Http.httpResponse.ContentAsUTF8 = builder.ToJson();
m_request.ProcessEnd = true;
}
}
TraceLog.Trace("UpdateNotice.DoUpdateNotice success httpContextId {0}", req.HttpContextId);
return 0;
}
public static int DoUpdateNoticeLanguageContent(NoticeLanguageContent languageContent, JsonData Jsondata, DBOperator dbOperator)
{
foreach (var language in languageContent.contentList)
{
Dictionary<string, string> from = new Dictionary<string, string>();
from.Add("noticeId", Convert.ToString(languageContent.noticeId));
from.Add("startTime", languageContent.startTime == "" ? DateTime.MinValue.ToString("G") : languageContent.startTime);
from.Add("endTime", languageContent.endTime == "" ? DateTime.MaxValue.ToString("G") : languageContent.endTime);
from.Add("state", Convert.ToString(languageContent.state));
from.Add("jump", languageContent.jump);
from.Add("jumpParam", languageContent.jumpParam);
from.Add("popUp", languageContent.popUp);
from.Add("sort", Convert.ToString(languageContent.sort));
from.Add("link", languageContent.link);
from.Add("triggertype", languageContent.triggertype);
from.Add("startTimeDay", languageContent.startTimeDay);
from.Add("startTimefine", languageContent.startTimefine);
from.Add("Giftbagcustoms", Convert.ToString(languageContent.giftbagcustoms));
from.Add("endTimeDay", languageContent.endTimeDay);
from.Add("endTimefine", languageContent.endTimefine);
from.Add("dungeonid", languageContent.dungeonid);
from.Add("Intervaldays", languageContent.Intervaldays == "" ? "0" : languageContent.Intervaldays);
from.Add("isshowtimetext", languageContent.isshowtimetext);
from.Add("aotupop", Convert.ToString(languageContent.aotupop));
from.Add("noticeType", languageContent.type.ToString());
from.Add("popType", languageContent.popType.ToString());
from.Add("timeParamStr", languageContent.timeParamStr);
from.Add("pageType", languageContent.pageType.ToString());
string areaNameListStr = "";
if (languageContent.areaNameList != null && languageContent.areaNameList.Count != 0)
{
foreach (var item in languageContent.areaNameList)
{
areaNameListStr = areaNameListStr + item + "|";
}
}
from.Add("areaNameList", areaNameListStr);
from.Add("customRealmStr", languageContent.customRealmStr);
string textParamList = "";
foreach (string text in languageContent.textParamList)
{
if (textParamList != "")
{
textParamList += "#";
}
textParamList += text;
}
from.Add("textParamList", textParamList);
from.Add("language", language.language);
from.Add("content", language.content);
from.Add("title", language.title);
from.Add("icon", language.icon);
from.Add("pic", language.pic);
from.Add("id", Convert.ToString(language.id));
//图片url如果是 http开头则前台未更改
//如果是data:image开头说明是新上传的
//数据库储存http路径
//http图片文件夹访问url
if (language.icon != "" && language.icon.StartsWith("data:image"))
{
string imgHttp = OperationServerUtils.GetServerConfig().imghttp;
language.icon = imgHttp + OperationServerUtils.Base64StringToFile(language.icon, language.id + "icon");
}
else if (!string.IsNullOrWhiteSpace(language.icon) && !language.icon.StartsWith("http"))
{
throw new InvalidOperationException("UpdateNotice.DoUpdateNotice icon field data is not recognized.");
}
if (language.pic != "" && language.pic.StartsWith("data:image"))
{
string imgHttp = OperationServerUtils.GetServerConfig().imghttp;
language.pic = imgHttp + OperationServerUtils.Base64StringToFile(language.pic, language.id + "pic");
}
else if (!string.IsNullOrWhiteSpace(language.pic) && !language.pic.StartsWith("http"))
{
throw new InvalidOperationException("UpdateNotice.DoUpdateNotice Pic field data is not recognized.");
}
string realmlist = languageContent.realmlist;
string timeParamStr = languageContent.timeParamStr;
// realm 解析
if (!string.IsNullOrEmpty(languageContent.customRealmStr))
{
string realmStr;
ParseRalm(languageContent.customRealmStr, timeParamStr, out realmStr);
realmlist = realmlist + "#" + realmStr;
}
if (!string.IsNullOrEmpty(areaNameListStr))
{
foreach (var item in areaNameListStr.Split("|"))
{
string realmStr;
ParseRalm(item, timeParamStr, out realmStr);
realmlist = realmlist + "#" + realmStr;
}
}
from.Add("realmlist", languageContent.realmlist);
from.Add("realmReallist", realmlist);
//扩展data
ExtNotice ext = new ExtNotice();
ext.Havedata = true;
ext.Type = from["popType"].Toint32(0);
ext.RealmListStr.SetString(from["realmReallist"]);
if (!string.IsNullOrEmpty(from["textParamList"]))
{
var textParamsList = from["textParamList"].Split("#");
foreach (var text in textParamsList)
{
if (!string.IsNullOrEmpty(text))
{
ext.TextParams.Add(text);
}
}
}
byte[] dataByte = StructMessageParseUtils.ToByteArray(ref ext);
from.Add("seq",WebsiteSvc.UpdateNoticeSeq().ToString());
dbOperator.DBUpdateNotice(from, dataByte, Jsondata);
DoSysNotice(from, ext);
}
return 0;
}
public static int DoSysNotice(Dictionary<string, string> from, ExtNotice ext)
{
if (from.Count < 0)
{
TraceLog.Error("UpdateNotice.DoSysNotice from.Count {0}", from.Count);
return -1;
}
foreach(var item in from)
TraceLog.Trace("UpdateNotice.DoSysNotice id {0},key {1}:", item.Key, item.Value);
SSSysNotice notice = new SSSysNotice();
notice.Id = int.Parse(from["id"]);
notice.Title.SetString(from["title"]);
notice.Content.SetString(from["content"]);
notice.StartTime = OperationServerUtils.GetTimeStamp(DateTime.Parse(from["startTime"]));
notice.EndTime = OperationServerUtils.GetTimeStamp(DateTime.Parse(from["endTime"]));
notice.Icon.SetString(from["icon"]);
notice.Pic.SetString(from["pic"]);
notice.Language.SetString(from["language"]);
notice.Popup = int.Parse(from["popUp"]);
notice.Jump = int.Parse(from["jump"]);
notice.JumpParam = from["jumpParam"] == "" ? 0 : int.Parse(from["jumpParam"]);
notice.State = int.Parse(from["state"]);
notice.Sort = int.Parse(from["sort"]);
notice.Link.SetString(from["link"]);
notice.Dungeonid = int.Parse(from["dungeonid"]);
notice.Uptime = OperationServerUtils.GetTimeStamp(DateTime.Now);
notice.Intervaldays = from["Intervaldays"].Toint32(0);
notice.Showtimetext = int.Parse(from["isshowtimetext"]) == 1;
notice.Giftbagcustoms = int.Parse(from["Giftbagcustoms"]);
notice.NoticeId = int.Parse(from["noticeId"]);
switch (from["triggertype"])
{
case "0":
default:
notice.Triggertype = NoticeTriggerType.FixedTime;
break;
case "1":
notice.Triggertype = NoticeTriggerType.OpeningTime;
break;
}
notice.Openserverstartday = from["startTimeDay"].Toint32(0);
notice.Openserverstarttime.SetString(from["startTimefine"]);
notice.Openserverendday = from["endTimeDay"].Toint32(0);
notice.Openserverendtime.SetString(from["endTimefine"]);
notice.Aotupop = int.Parse(from["aotupop"]) == 1;
notice.Type = int.Parse(from["noticeType"]);
notice.ExtNotice = ext;
notice.PageType = int.Parse(from["pageType"]);
notice.Seq = int.Parse(from["seq"]);
//显示状态
if (from["state"].Toint32(0) == 1)
{
if (SendNoticeSvc.NeedSendVersionServer(notice.Type))
{
OperationServerUtils.GetPacketSender().Broadcast((int) ServerType.Version,
(int) SSGameMsgID.ChatNoticeReq, ref notice, 0, 0);
}
else
{
OperationServerUtils.SendToWorld((int)SSGameMsgID.ChatNoticeReq, ref notice, 0, 0, from["realmlist"]);
}
}
//隐藏状态通知删除
else
{
if (from["realmlist"].Contains(','))
{
var realms = from["realmlist"].Split(',');
if (realms.Length <= 6)
{
foreach (var _RealmID in realms)
{
int RealmID = Convert.ToInt32(_RealmID);
if (RealmID != 0)
{
notice.Realmlist.Add(RealmID);
}
}
}
}
else
{
if (from["realmlist"] != "" && from["realmlist"] != null)
{
int RealmID = Convert.ToInt32(from["realmlist"]);
if (RealmID != 0)
{
notice.Realmlist.Add(RealmID);
}
}
}
SSSysNoticeDel noticeDel = new SSSysNoticeDel();
noticeDel.Id = notice.Id;
noticeDel.Popup = notice.Popup;
noticeDel.Triggertype = notice.Triggertype;
noticeDel.Realmlist.CopyFrom(ref notice.Realmlist);
if (SendNoticeSvc.NeedSendVersionServer(notice.Type))
{
OperationServerUtils.GetPacketSender().Broadcast((int)ServerType.Version,
(int)SSGameMsgID.ChatDelNotice, ref notice, 0, 0);
}
else
{
OperationServerUtils.SendToWorld((int)SSGameMsgID.ChatDelNotice, ref noticeDel, 0, 0, from["realmlist"]);
}
}
return 0;
}
public static void ParseRalm(string realmStr, string timeStr, out string parseRealmStr)
{
parseRealmStr = "";
int timeStart = 0;
int timeEnd = 0;
if(realmStr == "")
{
return;
}
try
{
if (!string.IsNullOrEmpty(timeStr))
{
var timeStrList = timeStr.Split("#", StringSplitOptions.RemoveEmptyEntries);
if(timeStrList.Length == 1)
{
if (timeStr[0] == '#')
timeEnd = OperationServerUtils.GetTimeStamp(Convert.ToDateTime(timeStrList[0]));
else
timeStart = OperationServerUtils.GetTimeStamp(Convert.ToDateTime(timeStrList[0]));
}
if(timeStrList.Length == 2)
{
timeStart = OperationServerUtils.GetTimeStamp(Convert.ToDateTime(timeStrList[0]));
timeEnd = OperationServerUtils.GetTimeStamp(Convert.ToDateTime(timeStrList[1]));
}
}
}
catch (Exception ex)
{
TraceLog.Error("UpdateNotice.ParseRalm time Parse Error : {0}!", ex.Message);
}
if (realmStr.Contains("#") || realmStr.Contains("-"))
{
parseRealmStr = realmStr;
}
else // 整个区服选择:TW,SEA
{
var serverData = OperationServerUtils.GetOperationServerData();
var realmId = 0;
List<int> realmIdList = new List<int>();
foreach (var realm in serverData.m_allRealm.Values)
{
if (realm.areaName == realmStr)
{
if (timeEnd == 0 && timeStart == 0)
{
realmId = realm.realmId;
var realmIdArea = realmId / 10000;
parseRealmStr = (realmIdArea * 10000).ToString() + "-" + (realmIdArea * 10000 + 99999).ToString();
return;
}
else
{
if (timeStart == 0 && timeEnd != 0)
{
if (realm.openTime < timeEnd)
{
realmIdList.Add(realm.realmId);
}
continue;
}
if (timeEnd == 0 && timeStart != 0)
{
if (realm.openTime > timeStart)
{
realmIdList.Add(realm.realmId);
}
continue;
}
if (timeEnd != 0 && timeStart != 0)
{
if (realm.openTime < timeEnd && realm.openTime > timeStart)
realmIdList.Add(realm.realmId);
continue;
}
}
}
}
realmIdList.Sort((x, y) => x.CompareTo(y));
List<RealmPos> posList = new List<RealmPos>();
if (realmIdList.Count == 1)
{
var realmPos = new RealmPos();
realmPos.Begin = realmIdList[0];
realmPos.End = realmIdList[0];
posList.Add(realmPos);
}
else if (realmIdList.Count == 2)
{
if (realmIdList[0] + 1 == realmIdList[1])
{
var realmPos = new RealmPos();
realmPos.Begin = realmIdList[0];
realmPos.End = realmIdList[1];
posList.Add(realmPos);
}
else
{
var realmPos1 = new RealmPos();
realmPos1.Begin = realmIdList[0];
realmPos1.End = realmIdList[0];
posList.Add(realmPos1);
var realmPos2 = new RealmPos();
realmPos2.Begin = realmIdList[1];
realmPos2.End = realmIdList[1];
posList.Add(realmPos2);
}
}
else
{
for (int i = 0; i < realmIdList.Count; i++)
{
var realmPos = new RealmPos();
realmPos.Begin = realmIdList[i];
for (int j = i; j < realmIdList.Count - 1; j++)
{
//列表连续
if (realmIdList[j + 1] == realmIdList[j] + 1)
{
i = j+1;
continue;
}
else
{
realmPos.End = realmIdList[i];
break;
}
}
if (realmPos.End == 0)
{
realmPos.End = realmIdList[i];
}
posList.Add(realmPos);
}
}
// 因为realmid在这里排序过后肯定是连续的
for (int i = 0; i < posList.Count; i++)
{
string tempStr = "";
if (timeStart == 0 && i == 0)
{
var realmIdArea = posList[i].Begin / 10000;
tempStr = tempStr + (realmIdArea * 10000).ToString();
}
else
{
tempStr = tempStr + posList[i].Begin.ToString();
}
tempStr = tempStr + "-";
if (timeEnd == 0 && i == posList.Count - 1)
{
var realmIdArea = posList[i].Begin / 10000;
tempStr = tempStr + (realmIdArea * 10000 + 99999).ToString();
}
else
{
tempStr = tempStr + posList[i].End.ToString();
}
parseRealmStr = parseRealmStr + tempStr + "#";
}
}
return;
}
}
}