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.
262 lines
10 KiB
262 lines
10 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
using Sog;
|
|
using MySql.Data.MySqlClient;
|
|
|
|
using SimpleHttpServer;
|
|
using LitJson;
|
|
|
|
using ProtoCSStruct;
|
|
|
|
namespace Operation
|
|
{
|
|
public class SendNoticeSvc : BaseReloadableService
|
|
{
|
|
public const int NoticeDataBuffLengthMax = 1 * 1024;
|
|
|
|
private static long m_lastTickTime = 0;
|
|
public MySqlDB m_mySqlDb;
|
|
|
|
//只有选择版本类型的公告才发往版本服务器
|
|
public static bool NeedSendVersionServer(int noticeType)
|
|
{
|
|
if(noticeType == (int)SSNoticeType.VersionServer)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public override int GetServiceType()
|
|
{
|
|
return OperationServiceType.SendNoticeSvc;
|
|
}
|
|
|
|
public override void Dispose()
|
|
{
|
|
m_mySqlDb.Dispose();
|
|
m_mySqlDb = null;
|
|
}
|
|
|
|
public SendNoticeSvc()
|
|
{
|
|
var config = OperationServerUtils.GetServerConfig();
|
|
m_mySqlDb = new MySqlDB(config.dbname,
|
|
config.dbip,
|
|
config.dbuser,
|
|
config.dbpassword);
|
|
}
|
|
|
|
public void OnTickSendNotice()
|
|
{
|
|
string sql = "SELECT * from notice WHERE state = 1 ";
|
|
|
|
// 将过期的notice状态置为0
|
|
List<int> ids = new List<int>();
|
|
MySqlDataReader reader = null;
|
|
|
|
try
|
|
{
|
|
reader = m_mySqlDb.ExecReader(sql);
|
|
|
|
while (reader.Read())
|
|
{
|
|
SSSysNotice notice = new SSSysNotice();
|
|
|
|
notice.Id = reader.GetInt32("id");
|
|
notice.NoticeId = reader.GetInt32("noticeId");
|
|
notice.StartTime = OperationServerUtils.GetTimeStamp(reader.GetDateTime("startTime"));
|
|
notice.EndTime = OperationServerUtils.GetTimeStamp(reader.GetDateTime("endTime"));
|
|
|
|
long nowSec = OperationServerUtils.GetTimeSecond();
|
|
|
|
TraceLog.Debug("SendNoticeSvc.OnTickSendNotice: id {0}, noticeId {1}, nowSec {2}, StartTime {3}, EndTime {4}", notice.Id, notice.NoticeId, nowSec, notice.StartTime, notice.EndTime);
|
|
|
|
if (reader.GetInt32("triggertype") != 1 && nowSec > notice.EndTime + 24 * 60 * 60)
|
|
{
|
|
ids.Add(notice.Id);
|
|
continue;
|
|
}
|
|
|
|
notice.Uptime = OperationServerUtils.GetTimeStamp(reader.GetDateTime("updatetime"));
|
|
notice.Title.SetString(reader.GetString("title"));
|
|
notice.Content.SetString(reader.GetString("content"));
|
|
notice.Icon.SetString(reader.GetString("icon"));
|
|
notice.Pic.SetString(OperationServerUtils.GetNewPicUrl(reader.GetString("pic")));
|
|
notice.Jump = reader.GetInt32("jump");
|
|
notice.JumpParam = reader.GetInt32("jumpParam");
|
|
notice.Sort = reader.GetInt32("sort");
|
|
notice.Popup = reader.GetInt32("popUp");
|
|
notice.Link.SetString(reader.GetString("link"));
|
|
notice.State = reader.GetInt32("state");
|
|
notice.Intervaldays = reader.GetInt32("Intervaldays");
|
|
notice.Language.SetString(reader.GetString("language"));
|
|
|
|
switch (reader.GetInt32("triggertype"))
|
|
{
|
|
case 2:
|
|
notice.Triggertype = NoticeTriggerType.Timer;
|
|
break;
|
|
case 1:
|
|
notice.Triggertype = NoticeTriggerType.OpeningTime;
|
|
break;
|
|
case 0:
|
|
default:
|
|
notice.Triggertype = NoticeTriggerType.FixedTime;
|
|
break;
|
|
}
|
|
|
|
notice.Dungeonid = reader.GetInt32("dungeonid");
|
|
|
|
var realmliststr = reader.GetString("realmlist");
|
|
if (!string.IsNullOrWhiteSpace(realmliststr))
|
|
{
|
|
foreach (var realm in realmliststr.Split(','))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(realm))
|
|
{
|
|
notice.Realmlist.Add(realm.Toint32(0));
|
|
}
|
|
}
|
|
}
|
|
|
|
notice.IsAllSvr = (realmliststr == "0");
|
|
notice.Openserverstartday = reader.GetInt32("openserverstartday");
|
|
notice.Openserverstarttime.SetString(reader.GetString("openserverstarttime"));
|
|
notice.Openserverendday = reader.GetInt32("openserverendday");
|
|
notice.Openserverendtime.SetString(reader.GetString("openserverendtime"));
|
|
notice.Showtimetext = reader.GetBoolean("isshowtimetext");
|
|
notice.Aotupop = reader.GetBoolean("aotupop");
|
|
|
|
notice.Giftbagcustoms = reader.GetInt32("Giftbagcustoms");
|
|
notice.Type = reader.GetInt32("noticeType");
|
|
notice.PageType = reader.GetInt32("pageType");
|
|
notice.Seq = reader.GetInt32("seq");
|
|
|
|
ExtNotice ext = new ExtNotice();
|
|
|
|
//请封装
|
|
int gameDataIndex = reader.GetOrdinal("data");
|
|
if (!reader.IsDBNull(gameDataIndex))
|
|
{
|
|
byte[] buffer = new byte[NoticeDataBuffLengthMax];
|
|
long gameDataLength = reader.GetBytes(gameDataIndex, 0, buffer, 0, buffer.Length);
|
|
byte[] gameDataByte = new byte[gameDataLength];
|
|
Buffer.BlockCopy(buffer, 0, gameDataByte, 0, (int)gameDataLength);
|
|
|
|
StructMessageParseUtils.ParseFrom(ref ext, gameDataByte);
|
|
}
|
|
|
|
notice.ExtNotice = ext;
|
|
|
|
if (!string.IsNullOrEmpty(notice.ExtNotice.RealmListStr.GetString()))
|
|
{
|
|
realmliststr = notice.ExtNotice.RealmListStr.GetString();
|
|
}
|
|
|
|
if (NeedSendVersionServer(notice.Type))
|
|
{
|
|
OperationServerUtils.GetPacketSender().Broadcast((int)ServerType.Version,
|
|
(int)SSGameMsgID.ChatNoticeReq, ref notice, 0, 0);
|
|
|
|
TraceLog.Debug("SendNoticeSvc.OnTickSendNotice send2Version: id {0}, noticeId {1}, nowSec {2}, StartTime {3}, EndTime {4}", notice.Id, notice.NoticeId, nowSec, notice.StartTime, notice.EndTime);
|
|
}
|
|
else
|
|
{
|
|
OperationServerUtils.SendToWorld((int)SSGameMsgID.ChatNoticeReq, ref notice, 0, 0, realmliststr);
|
|
|
|
TraceLog.Debug("SendNoticeSvc.OnTickSendNotice send2World: id {0}, noticeId {1}, nowSec {2}, StartTime {3}, EndTime {4}", notice.Id, notice.NoticeId, nowSec, notice.StartTime, notice.EndTime);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
TraceLog.Error("SendNoticeSvc.OnTickSendNotice error: {0}", e.Message);
|
|
}
|
|
if(reader != null)
|
|
{
|
|
reader.Close();
|
|
}
|
|
if (ids.Count > 0)
|
|
{
|
|
string idList = ids[0].ToString();
|
|
if (ids.Count > 1)
|
|
{
|
|
for (int i = 1; i < ids.Count(); i++)
|
|
{
|
|
idList = idList + "," + ids[i];
|
|
}
|
|
}
|
|
sql = string.Format("Update notice set state = 0 WHERE id in ({0});", idList);
|
|
reader = m_mySqlDb.ExecReader(sql);//运行sql语句得出返回值给reader
|
|
if (reader == null)
|
|
{
|
|
TraceLog.Trace("SendNoticeSvc.OnTickSendNotice 连接数据库异常");
|
|
}
|
|
reader.Close();
|
|
}
|
|
}
|
|
|
|
public void OnTick(long nowMs)
|
|
{
|
|
//60秒一次
|
|
if (nowMs - m_lastTickTime < 60000)
|
|
{
|
|
return;
|
|
}
|
|
|
|
m_lastTickTime = nowMs;
|
|
|
|
OnTickSendNotice();
|
|
|
|
NoticeBackGroundsTick();
|
|
}
|
|
|
|
public void NoticeBackGroundsTick()
|
|
{
|
|
// 查询待发布的图片
|
|
string sql = "SELECT * from noticebackgrounds WHERE state=1 ORDER BY startTime DESC ";
|
|
|
|
MySqlDataReader reader = null;
|
|
|
|
try
|
|
{
|
|
reader = m_mySqlDb.ExecReader(sql);
|
|
|
|
while (reader.Read())
|
|
{
|
|
int id = reader.GetInt32("id");
|
|
int startTime = OperationServerUtils.GetTimeStamp(reader.GetDateTime("startTime"));
|
|
string language = reader.GetString("language");
|
|
if (OperationServerUtils.GetTimeStamp(DateTime.Now) >= startTime)
|
|
{
|
|
SSNoticeBackGroundsRes res = new SSNoticeBackGroundsRes();
|
|
res.Uid = 0;
|
|
|
|
var picObj = new NoticeBackGrounds();
|
|
picObj.Language.SetString(reader.GetString("language"));
|
|
|
|
picObj.Pic.SetString(OperationServerUtils.GetNewPicUrl(reader.GetString("pic")));
|
|
|
|
res.PicList.Add(picObj);
|
|
OperationServerUtils.SendToWorld((int)SSGameMsgID.NoticeBackgroundsRes, ref res, 0, 0, "");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
TraceLog.Error("SendNoticeSvc.NoticeBackGroundsTick - UpdateState : error: {0}", e.Message);
|
|
}
|
|
|
|
if(reader != null)
|
|
{
|
|
reader.Close();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|