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.
390 lines
15 KiB
390 lines
15 KiB
using System;
|
|
using System.Collections.Generic;
|
|
|
|
using Sog;
|
|
using LitJson;
|
|
using SimpleHttpServer;
|
|
using MySql.Data.MySqlClient;
|
|
using System.IO;
|
|
using ProtoCSStruct;
|
|
|
|
|
|
|
|
namespace Operation
|
|
{
|
|
public enum StateEnum
|
|
{
|
|
None = 0,
|
|
published = 1,
|
|
Frobidden = 2
|
|
}
|
|
|
|
public class NoticeBackgrounds
|
|
{
|
|
public int id;
|
|
public int state;
|
|
public string language;
|
|
public string startTime;
|
|
public string endTime;
|
|
public string pic;
|
|
}
|
|
|
|
[MenuMapping(refc = typeof(SendEmail))]
|
|
class SysNoticeBackgroungs
|
|
{
|
|
[RequestMapping("更新公告背景图",PermissionCode.UPDATE_NOTICE_BACKGROUNDS, toLog: true)]
|
|
public static int OnUpdateNoticeBackGroundsHttpReq(string httpApiCmd, JsonData Jsondata, HttpResponse rsp, HttpRequest request, HttpQueryParams query, uint httpContextId)
|
|
{
|
|
TraceLog.Trace("SysNoticeBackgroungs.OnUpdateNoticeBackGroundsHttpReq url {0} ,param count {1}, httpContextId {2}", request.Url, query.Count, httpContextId);
|
|
|
|
NoticeBackgrounds reqBackgrounds = request.Content.ToJson<NoticeBackgrounds>();
|
|
|
|
string language = reqBackgrounds.language == null ? "" : reqBackgrounds.language;
|
|
string pic = reqBackgrounds.pic == null ? "" : reqBackgrounds.pic;
|
|
int id = reqBackgrounds.id;
|
|
int state = reqBackgrounds.state;
|
|
string startTime = reqBackgrounds.startTime == "" ? DateTime.MinValue.ToString() : reqBackgrounds.startTime;
|
|
string endTime = reqBackgrounds.endTime == "" ? DateTime.MaxValue.ToString() : reqBackgrounds.endTime;
|
|
|
|
//提交记得打开
|
|
if (pic != "" && pic.StartsWith("data:image"))
|
|
{
|
|
string imgHttp = OperationServerUtils.GetServerConfig().imghttp;
|
|
pic = imgHttp + OperationServerUtils.Base64StringToFile(pic, id + "pic");
|
|
}
|
|
|
|
if (String.IsNullOrEmpty(language) || String.IsNullOrEmpty(pic))
|
|
{
|
|
TraceLog.Error("SysNoticeBackgroungs.OnUpdateNoticeBackGroundsHttpReq param error!");
|
|
Jsondata["ret"] = 3;
|
|
Jsondata["msg"] = "参数错误";
|
|
return 3;
|
|
}
|
|
|
|
RepeatedFixedStructString128_10 data = new RepeatedFixedStructString128_10();
|
|
data.Add(language);
|
|
data.Add(pic);
|
|
data.Add(id.ToString());
|
|
data.Add(state.ToString());
|
|
data.Add(startTime);
|
|
data.Add(endTime);
|
|
HttpApiRootHandler.FillHttpApiDbReq2MessageTaskDistributor(httpApiCmd, httpContextId, ref data);
|
|
|
|
rsp.IsWaitFor = true;
|
|
|
|
TraceLog.Trace("SysNoticeBackgroungs.OnUpdateNoticeBackGroundsHttpReq httpContextId {0}", httpContextId);
|
|
|
|
return 0;
|
|
}
|
|
|
|
public static int DoUpdateNoticeBackGrounds(string httpApiCmd, SSHttpApiDbReq req, DBOperator dbOperator)
|
|
{
|
|
TraceLog.Trace("SysNoticeBackgroungs.DoUpdateNoticeBackGrounds HttpContextId {0}", req.HttpContextId);
|
|
|
|
HttpRequestInfo m_request = null;
|
|
LitJson.JsonData builder = new LitJson.JsonData();
|
|
string language = "";
|
|
string pic = "";
|
|
int state = 0;
|
|
string startTime = "";
|
|
|
|
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("SysNoticeBackgroungs.DoUpdateNoticeBackGrounds param error");
|
|
builder["ret"] = 2;
|
|
builder["msg"] = "参数错误";
|
|
m_request.Http.httpResponse.ContentAsUTF8 = builder.ToJson();
|
|
m_request.ProcessEnd = true;
|
|
return 2;
|
|
}
|
|
else
|
|
{
|
|
language = req.Data[0].ToString();
|
|
pic = req.Data[1].ToString();
|
|
state = int.Parse(req.Data[3].ToString());
|
|
startTime = req.Data[4].ToString();
|
|
|
|
dbOperator.DBUpdateNoticeBackGrounds(language, pic, int.Parse(req.Data[2].ToString()), state, startTime, req.Data[5].ToString(), builder);
|
|
|
|
m_request.Http.httpResponse.ContentAsUTF8 = builder.ToJson();
|
|
m_request.ProcessEnd = true;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TraceLog.Error("SysNoticeBackgroungs.DoUpdateNoticeBackGrounds error : {0}", ex.Message);
|
|
builder["ret"] = 3;
|
|
builder["msg"] = "数据库操作错误!";
|
|
if(m_request!=null)
|
|
{
|
|
m_request.Http.httpResponse.ContentAsUTF8 = builder.ToJson();
|
|
m_request.ProcessEnd = true;
|
|
}
|
|
return 3;
|
|
}
|
|
|
|
if (OperationServerUtils.GetTimeStamp(DateTime.Now) >= OperationServerUtils.GetTimeStamp(DateTime.Parse(startTime)))
|
|
{
|
|
// TODO: 发送到聊天服务器
|
|
SSNoticeBackGroundsRes notice = new SSNoticeBackGroundsRes();
|
|
|
|
var picObj = new NoticeBackGrounds();
|
|
|
|
picObj.Language.SetString(language);
|
|
picObj.Language.SetString(pic);
|
|
|
|
if (state != (int)StateEnum.published)
|
|
{
|
|
picObj.Language.SetString("");
|
|
}
|
|
notice.PicList.Add(picObj);
|
|
|
|
OperationServerUtils.SendToWorld((int)SSGameMsgID.NoticeBackgroundsRes, ref notice, 0, 0, "");
|
|
}
|
|
|
|
TraceLog.Trace("SysNoticeBackgroungs.DoUpdateNoticeBackGrounds success httpContextId {0}", req.HttpContextId);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
[RequestMapping("公告背景图",PermissionCode.SELECT_NOTICE_BACKGROUNDS,true, toLog: true)]
|
|
public static int OnSelectNoticeBackGroundsHttpReq(string httpApiCmd, JsonData Jsondata, HttpResponse rsp, HttpRequest request, HttpQueryParams query, uint httpContextId)
|
|
{
|
|
TraceLog.Trace("SysNoticeBackgroungs.OnSelectNoticeBackGroundsHttpReq url {0} ,param count {1}, httpContextId {2}", request.Url, query.Count, httpContextId);
|
|
|
|
string language = query.GetValue("language");
|
|
string id = query.GetValue("id");
|
|
|
|
if (!String.IsNullOrEmpty(language))
|
|
{
|
|
if (language.Length > 5)
|
|
{
|
|
TraceLog.Error("SysNoticeBackgroungs.OnSelectNoticeBackGroundsHttpReq language.Length 过长");
|
|
Jsondata["ret"] = 7;
|
|
Jsondata["msg"] = "输入参数错误";
|
|
return 7;
|
|
}
|
|
}
|
|
|
|
if (!String.IsNullOrEmpty(id))
|
|
{
|
|
if (query.GetValue("id").Toint32(0) <= 0)
|
|
{
|
|
Jsondata["ret"] = 7;
|
|
Jsondata["msg"] = "输入参数错误";
|
|
return 7;
|
|
}
|
|
}
|
|
|
|
RepeatedFixedStructString128_10 data = new RepeatedFixedStructString128_10();
|
|
data.Add(language);
|
|
data.Add(id);
|
|
HttpApiRootHandler.FillHttpApiDbReq2MessageTaskDistributor(httpApiCmd, httpContextId, ref data);
|
|
|
|
rsp.IsWaitFor = true;
|
|
|
|
TraceLog.Trace("SysNoticeBackgroungs.OnSelectNoticeBackGroundsHttpReq id {0}", id);
|
|
|
|
return 0;
|
|
}
|
|
|
|
public static int DoSelectNoticeBackGrounds(string httpApiCmd, SSHttpApiDbReq req, DBOperator dbOperator)
|
|
{
|
|
TraceLog.Trace("SysNoticeBackgroungs.DoSelectNoticeBackGrounds 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 < 2)
|
|
{
|
|
TraceLog.Error("SysNoticeBackgroungs.DoSelectNoticeBackGrounds : id == 0");
|
|
builder["ret"] = 2;
|
|
builder["msg"] = "参数错误";
|
|
}
|
|
else
|
|
dbOperator.DBSelectNoticeBackGrounds(req.Data[0].ToString(), req.Data[1].ToString(), builder);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TraceLog.Error("SysNoticeBackgroungs.DoSelectNoticeBackGrounds Error Msg {0}", ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
if (m_request != null)
|
|
{
|
|
m_request.Http.httpResponse.ContentAsUTF8 = builder.ToJson();
|
|
m_request.ProcessEnd = true;
|
|
}
|
|
}
|
|
|
|
TraceLog.Trace("SysNoticeBackgroungs.DoSelectNoticeBackGrounds success httpContextId {0}", req.HttpContextId);
|
|
|
|
return 0;
|
|
}
|
|
|
|
[RequestMapping("删除公告背景图",PermissionCode.DEL_NOTICE_BACKGROUNDS, toLog: true)]
|
|
public static int OnDeleteNoticeBackGroundsHttpReq(string httpApiCmd, JsonData Jsondata, HttpResponse rsp, HttpRequest request, HttpQueryParams query, uint httpContextId)
|
|
{
|
|
TraceLog.Trace("SysNoticeBackgroungs.OnDeleteNoticeBackGroundsHttpReq url {0} ,param count {1}, httpContextId {2}", request.Url, query.Count, httpContextId);
|
|
|
|
int id = query.GetValue("id").Toint32(0);
|
|
if(id == 0)
|
|
{
|
|
TraceLog.Error("SysNoticeBackgroungs.OnDeleteNoticeBackGroundsHttpReq : id == 0");
|
|
Jsondata["ret"] = 2;
|
|
Jsondata["msg"] = "参数Id错误";
|
|
return 2;
|
|
}
|
|
|
|
RepeatedFixedStructString128_10 data = new RepeatedFixedStructString128_10();
|
|
data.Add(id.ToString());
|
|
HttpApiRootHandler.FillHttpApiDbReq2MessageTaskDistributor(httpApiCmd, httpContextId, ref data);
|
|
|
|
rsp.IsWaitFor = true;
|
|
|
|
TraceLog.Trace("SysNoticeBackgroungs.OnDeleteNoticeBackGroundsHttpReq id {0}", id);
|
|
|
|
return 0;
|
|
}
|
|
|
|
public static int DoDeleteNoticeBackGrounds(string httpApiCmd, SSHttpApiDbReq req, DBOperator dbOperator)
|
|
{
|
|
TraceLog.Trace("SysNoticeBackgroungs.DoDeleteNoticeBackGrounds 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("SysNoticeBackgroungs.DoDeleteNoticeBackGrounds param error");
|
|
builder["ret"] = 2;
|
|
builder["msg"] = "参数Id错误";
|
|
}
|
|
else
|
|
dbOperator.DBDeleteNoticeBackgrounds(int.Parse(req.Data[0].ToString()));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TraceLog.Error("SysNoticeBackgroungs.DoDeleteNoticeBackGrounds Error Msg {0}", ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
if (m_request != null)
|
|
{
|
|
m_request.Http.httpResponse.ContentAsUTF8 = builder.ToJson();
|
|
m_request.ProcessEnd = true;
|
|
}
|
|
}
|
|
|
|
TraceLog.Trace("SysNoticeBackgroungs.DeleteNoticeBackGrounds success httpContextId {0}", req.HttpContextId);
|
|
|
|
return 0;
|
|
}
|
|
|
|
public static void OnNoticeBackGroundsReq(uint serverID, StructPacket packet, DBOperator dbOperator)
|
|
{
|
|
ref var req = ref packet.GetMessage<SSNoticeBackGroundsReq>();
|
|
|
|
TraceLog.Debug("SysNoticeBackgroungs.OnNoticeBackGroundsReq: Language:{0}, uid:{1}", req.Language.GetString(), req.Uid);
|
|
|
|
SSNoticeBackGroundsRes res = new SSNoticeBackGroundsRes();
|
|
|
|
dbOperator.DBNoticeBackgrounds(req.Language.GetString(), ref res);
|
|
|
|
res.Uid = req.Uid;
|
|
OperationServerUtils.SendToWorld((int)SSGameMsgID.NoticeBackgroundsRes, ref res, 0, 0, "");
|
|
}
|
|
|
|
public static int OnUpdateNoticeBackGroundsStateHttpReq(string httpApiCmd, JsonData Jsondata, HttpResponse rsp, HttpRequest request, HttpQueryParams query, uint httpContextId)
|
|
{
|
|
TraceLog.Trace("SysNoticeBackgroungs.OnUpdateNoticeBackGroundsStateHttpReq url {0} ,param count {1}, httpContextId {2}", request.Url, query.Count, httpContextId);
|
|
|
|
int id = query.GetValue("id").Toint32(0);
|
|
int state = query.GetValue("state").Toint32(0);
|
|
|
|
if(id == 0 || state == 0)
|
|
{
|
|
Jsondata["ret"] = 2;
|
|
Jsondata["msg"] = "参数错误";
|
|
return 2;
|
|
}
|
|
|
|
RepeatedFixedStructString128_10 data = new RepeatedFixedStructString128_10();
|
|
data.Add(id.ToString());
|
|
data.Add(state.ToString());
|
|
HttpApiRootHandler.FillHttpApiDbReq2MessageTaskDistributor(httpApiCmd, httpContextId, ref data);
|
|
|
|
rsp.IsWaitFor = true;
|
|
|
|
TraceLog.Trace("SysNoticeBackgroungs.OnUpdateNoticeBackGroundsStateHttpReq id {0}", httpContextId);
|
|
|
|
return 0;
|
|
}
|
|
|
|
public static int DoUpdateNoticeBackGroundsState(string httpApiCmd, SSHttpApiDbReq req, DBOperator dbOperator)
|
|
{
|
|
TraceLog.Trace("SysNoticeBackgroungs.DoUpdateNoticeBackGroundsState 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 < 2)
|
|
{
|
|
TraceLog.Error("SysNoticeBackgroungs.DoUpdateNoticeBackGroundsState param error");
|
|
builder["ret"] = 2;
|
|
builder["msg"] = "参数Id错误";
|
|
}
|
|
else
|
|
{
|
|
bool ret = dbOperator.DBUpdateNoticeBackGroundsState(int.Parse(req.Data[0].ToString()), int.Parse(req.Data[1].ToString()));
|
|
if (!ret)
|
|
{
|
|
builder["ret"] = 6;
|
|
builder["msg"] = "修改错误";
|
|
}
|
|
else
|
|
{
|
|
builder["msg"] = "修改成功!";
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TraceLog.Error("SysNoticeBackgroungs.DoUpdateNoticeBackGroundsState Error Msg {0}", ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
if (m_request != null)
|
|
{
|
|
m_request.Http.httpResponse.ContentAsUTF8 = builder.ToJson();
|
|
m_request.ProcessEnd = true;
|
|
}
|
|
}
|
|
|
|
TraceLog.Trace("SysNoticeBackgroungs.DoUpdateNoticeBackGroundsState success httpContextId {0}", req.HttpContextId);
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
|