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.
 
 
 
 
 
 

898 lines
35 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Threading;
using Operation;
using Sog;
using LitJson;
using SimpleHttpServer;
using MySql.Data.MySqlClient;
using ProtoCSStruct;
using System.Collections;
using System.Globalization;
namespace Operation
{
public class MailJsonObj
{
public string timeLimit;
public string name;
public string itemstr;
public string realmlist;
public string curstr;
public string herolist;
public string uuid;
public int isSendToAll; // 是否进行语言校验
public int isReview; //是否需要审核
public List<languageContent> contentList;
public string equipStr;
public string versionParam;
public string playerCreateTime;
public string customItemStr;
public string timeParamStr;
public List<string> areaNameList;
public string customRealmStr;
}
public class languageContent
{
public string language;
public string title;
public string content;
public string senderName;
}
public enum RewordType
{
None = 0,
Cur = 1,
Item,
Hero,
Equip
}
[MenuMapping(MenuName.OPERATION_MANAGER,MenuIcon.TOOLS,4,PermissionCode.OPERATION_TOOLS)]
public class SendEmail
{
public static int SendEmailHero(string httpApiCmd, JsonData Jsondata, HttpResponse rsp, HttpRequest request, HttpQueryParams query, uint httpContextId)
{
string uid = query.GetValue("uid");
string language = query.GetValue("language");
string title = query.GetValue("title");
string content = query.GetValue("content");
string server_id = query.GetValue("server_id");
Dictionary<string, string> from = new Dictionary<string, string>();
from.Add("name", uid);
from.Add("language", language);
from.Add("title", title);
from.Add("content", content);
from.Add("realmlist", server_id);
from.Add("isSendToAll", "0");
from.Add("itemstr", "");
from.Add("timeLimit", (60 * 24 * 14).ToString());
from.Add("curstr", "");
from.Add("herolist", "");
string uuid = System.Guid.NewGuid().ToString();
from.Add("uuid", uuid);
// 暂时不要这个发送
//checkLastMail(Jsondata, rsp, request, query, from);
return 0;
}
public static int SendMail(JsonData Jsondata, MailJsonObj mailContent, DBOperator dbOperator)
{
TraceLog.Trace("SendEmail.SendMail uuid {0}", mailContent.uuid);
string language = "";
string name11 = mailContent.name == null ? "" : mailContent.name;
string realmlist11 = mailContent.realmlist == null ? "" : mailContent.realmlist;
string itemstr11 = mailContent.itemstr == null ? "" : mailContent.itemstr;
bool isReview = mailContent.isReview == 1;
string timeLimit11 = mailContent.timeLimit;
string[] startEnd = timeLimit11.Split("#");
bool asySend = false;
DateTime start = DateTime.ParseExact(startEnd[0], "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture);
DateTime end = DateTime.ParseExact(startEnd[1], "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture);
if ((end - start).TotalSeconds < 60*10)//600秒
{//必须大于1天
Jsondata["ret"] = 6;
Jsondata["code"] = 6;
Jsondata["msg"] = "时间配置不对,开始时间和结束小于10分钟";
Jsondata["data"] = null;
return 6;
}
if ((end.Day - start.Day) > 15)
{//必须小于15天
Jsondata["ret"] = 6;
Jsondata["code"] = 6;
Jsondata["msg"] = "时间配置不对,开始时间和结束大于15天 ";
Jsondata["data"] = null;
return 6;
}
long now = OperationServerUtils.GetApp().GetTimeSecond();
DateTime currentDate = DateTimeOffset.FromUnixTimeSeconds(now).LocalDateTime;
if (end < currentDate)
{
Jsondata["ret"] = 6;
Jsondata["code"] = 6;
Jsondata["msg"] = "结束时间配置不对 ";
Jsondata["data"] = null;
return 6;
}
if (start > end)
{
Jsondata["ret"] = 6;
Jsondata["code"] = 6;
Jsondata["msg"] = "开始时间和结束时间配置不对 ";
Jsondata["data"] = null;
return 6;
}
asySend = start > currentDate;
timeLimit11 = start.ToString("yyyy-MM-dd HH:mm:ss") + "#" + end.ToString("yyyy-MM-dd HH:mm:ss");
string curstr11 = mailContent.curstr == null ? "" : mailContent.curstr;
string equipStr11 = mailContent.equipStr == null ? "" : mailContent.equipStr;
string herolist11 = mailContent.herolist == null ? "" : mailContent.herolist;
string title11 = "";
string content11 = "";
string uuid = mailContent.uuid;
string timeParamStr = mailContent.timeParamStr == null ? "" : mailContent.timeParamStr;
string customItemStr = mailContent.customItemStr == null ? "" : mailContent.customItemStr;
int isSendToAll = mailContent.isSendToAll;
ExtMail exData = new ExtMail();
exData.Havedata = true;
if (mailContent.contentList.Count > 0)
{
exData.Havedata = true;
foreach (var item in mailContent.contentList)
{
MailLangContent tempItem = new MailLangContent();
tempItem.Language.SetString(item.language);
tempItem.Title.SetString(item.title);
tempItem.Content.SetString(item.content);
tempItem.SenderName.SetString(item.senderName);
exData.LangContentList.Add(tempItem);
TraceLog.Trace("SendEmail.SendMail uuid {0} language {1} title {2} content {3} senderName {4}", mailContent.uuid, item.language, item.title, item.content, item.senderName);
}
exData.VersionParam.SetString(mailContent.versionParam);
if (String.IsNullOrEmpty(mailContent.playerCreateTime))
{
//运营需求:只要没有设置玩家注册时间限制吗,邮件再有效期内,后注册的玩家可以收到邮件
exData.PlayerCreateTimeLimit =0; //(long)OperationServerUtils.GetTimeStamp(DateTime.Now);
}
else
{
exData.PlayerCreateTimeLimit = (long)OperationServerUtils.GetTimeStamp(DateTime.Parse(mailContent.playerCreateTime));
}
}
if (!string.IsNullOrEmpty(mailContent.customRealmStr))
{
string tempStr = "";
ParseRalm(mailContent.customRealmStr, mailContent.timeParamStr, out tempStr);
if (tempStr != "")
{
realmlist11 = realmlist11 + "#" + tempStr;
}
}
if (mailContent.areaNameList.Count != 0)
{
foreach (var item in mailContent.areaNameList)
{
string tempStr = "";
ParseRalm(item, mailContent.timeParamStr, out tempStr);
if (tempStr != "")
{
realmlist11 = realmlist11 + "#" + tempStr;
}
}
}
exData.RealmStr.SetString(realmlist11);
exData.TimeParamStr.SetString(timeParamStr);
byte[] dataByte = StructMessageParseUtils.ToByteArray(ref exData);
//一封邮件附件总数不超过12
int itemSum = itemstr11.Split("#").Length + herolist11.Split("#").Length + equipStr11.Split("#").Length;
if (itemSum > 12 || curstr11.Split("#").Length > 4)
{
Jsondata["ret"] = 6;
Jsondata["code"] = 6;
Jsondata["msg"] = "添加物品数量最多12种,货币最多4种 ";
Jsondata["data"] = null;
return 6;
}
//奖励合法性检查
string errmsg;
// 道具
if (!CheckItemStr(itemstr11, GoodsType.Items, out errmsg))
{
Jsondata["ret"] = 6;
Jsondata["code"] = 6;
Jsondata["msg"] = errmsg;
Jsondata["data"] = null;
return 6;
}
// 道具
if (!CheckItemStr(equipStr11, GoodsType.Equipment, out errmsg))
{
Jsondata["ret"] = 6;
Jsondata["code"] = 6;
Jsondata["msg"] = errmsg;
Jsondata["data"] = null;
return 6;
}
// 货币
if (!CheckItemStr(curstr11, GoodsType.Items, out errmsg))
{
Jsondata["ret"] = 6;
Jsondata["code"] = 6;
Jsondata["msg"] = errmsg;
Jsondata["data"] = null;
return 6;
}
var arrylist = name11.Split("|");
if (arrylist == null || arrylist.Length == 0)
{
Jsondata["ret"] = -1;
Jsondata["code"] = -1;
Jsondata["msg"] = "没有发送目标";
Jsondata["data"] = null;
return -1;
}
long uidparse = 0;
if (long.TryParse(arrylist[0], out uidparse))//是发给玩家的
{
int ret = 0;
if (isReview)
{
ret = dbOperator.DBInsertIntoMailBoxTempReview(name11, title11, content11, realmlist11, herolist11, language,
uuid, curstr11, itemstr11, timeLimit11, isSendToAll, equipStr11, dataByte, customItemStr);
}
else
{
if (asySend)
{
ret = dbOperator.DBInsertIntoMailBoxTemp(name11, title11, content11, realmlist11, herolist11, language,
uuid, curstr11, itemstr11, timeLimit11, isSendToAll, equipStr11, dataByte, customItemStr);
}
else
{
ret = dbOperator.DBInsertIntoMailBox(name11, title11, content11, realmlist11, herolist11, language,
uuid, curstr11, itemstr11, timeLimit11, isSendToAll, equipStr11, dataByte, customItemStr);
}
}
if (ret != 0)
{
TraceLog.Trace("SendEmail.SendMail数据库连接失败");
Jsondata["ret"] = ret;
Jsondata["msg"] = "写入数据库连接失败";
Jsondata["code"] = ret;
Jsondata["data"] = null;
return ret;
}
}
else
{
//all android ios 这些
foreach (var _name in name11.Split("|"))
{
if (_name.Length > 0)
{
int ret = 0;
if (isReview)
{
ret = dbOperator.DBInsertIntoMailBoxTempReview(name11, title11, content11, realmlist11, herolist11, language,
uuid, curstr11, itemstr11, timeLimit11, isSendToAll, equipStr11, dataByte, customItemStr);
}
else
{
if (asySend)
{
ret = dbOperator.DBInsertIntoMailBoxTemp(_name, title11, content11, realmlist11, herolist11, language,
uuid, curstr11, itemstr11, timeLimit11, isSendToAll, equipStr11, dataByte, customItemStr);
}
else
{
ret = dbOperator.DBInsertIntoMailBox(_name, title11, content11, realmlist11, herolist11, language,
uuid, curstr11, itemstr11, timeLimit11, isSendToAll, equipStr11, dataByte, customItemStr);
}
}
if (ret != 0)
{
TraceLog.Trace("数据库连接失败");
Jsondata["ret"] = ret;
Jsondata["msg"] = "写入数据库连接失败";
Jsondata["code"] = ret;
Jsondata["data"] = null;
return ret;
}
}
}
}
return 0;
}
[RequestMapping("邮件管理",PermissionCode.MAIL_SEND,true)]
public static int OnSendEmailHttpReq(string httpApiCmd, JsonData Jsondata, HttpResponse rsp, HttpRequest request, HttpQueryParams query, uint httpContextId)
{
TraceLog.Trace("SendEmail.OnSendEmailHttpReq url {0} ,param count {1} ,httpContextId {2}", request.Url, query.Count, httpContextId);
string account = OperationServerUtils.GetAccount(query.GetValue("token"));
if (account == null)
{
Jsondata["ret"] = 6;
Jsondata["msg"] = "账号不存在或未登录";
return 6;
}
var languageContent = request.Content.ToJson<MailJsonObj>();
TraceLog.Trace("SendEmail.OnSendEmailHttpReq httpContextId {0} account {1} languageContentUUid {2}", httpContextId, account, languageContent.uuid);
RepeatedFixedStructString128_10 data = new RepeatedFixedStructString128_10();
data.Add(account);
HttpApiRootHandler.FillHttpApiDbReq2MessageTaskDistributor(httpApiCmd, httpContextId, ref data);
rsp.IsWaitFor = true;
return 0;
}
public static int DoSendEmail(string httpApiCmd, SSHttpApiDbReq req, DBOperator dbOperator)
{
TraceLog.Trace("SendEmail.DoSendEmail 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("SendEmail.DoSendEmail param error");
builder["ret"] = 2;
builder["msg"] = "参数错误";
}
else
{
var languageContent = m_request.Http.httpRequest.Content.ToJson<MailJsonObj>();
TraceLog.Trace("SendEmail.DoSendEmail HttpContextId {0} languageContentUUid {1}", req.HttpContextId,
languageContent.uuid);
if (!dbOperator.DBCheckEmailExist(builder, languageContent) &&
!dbOperator.DBCheckEmailTempExist(builder, languageContent))
{
builder["msg"] = "发送邮件成功!";
builder["ret"] = 0;
var uidList = languageContent.name.Split("|");
if (uidList.Length > 500)
{
List<string> uidStrList = new List<string>();
string uidStr = "";
for (int i = 0; i < uidList.Length; i++)
{
if (i % 500 == 0 && i != 0)
{
string uidStrCopy = uidStr;
uidStrList.Add(uidStrCopy);
uidStr = "";
}
uidStr += (uidList[i] += "|");
}
if (uidStr != "")
{
uidStrList.Add(uidStr);
}
foreach (var item in uidStrList)
{
languageContent.name = item;
SendMail(builder, languageContent, dbOperator);
}
}
else
{
SendMail(builder, languageContent, dbOperator);
}
}
}
}
catch (Exception ex)
{
TraceLog.Error("SendEmail.DoSendEmail Error Msg {0}", ex.Message);
}
finally
{
if (m_request != null)
{
m_request.Http.httpResponse.ContentAsUTF8 = builder.ToJson();
m_request.ProcessEnd = true;
}
}
TraceLog.Trace("SendEmail.DoSendEmail success httpContextId {0}", req.HttpContextId);
return 0;
}
//hero舆情系统发送邮件请求
[RequestMapping("发送舆情系统邮件",PermissionCode.MAIL_SEND_CHAT,ignored:true)]
public static int OnSendMailHttpReq(string httpApiCmd, JsonData Jsondata, HttpResponse rsp, HttpRequest request, HttpQueryParams query, uint httpContextId)
{
TraceLog.Trace("SendEmail.OnSendMailHttpReq url {0} ,param count {1} ,httpContextId {2}", request.Url, query.Count, httpContextId);
string serverId = query.GetValue("server_id");
string uid = query.GetValue("role_id");
string title = query.GetValue("title");
string content = query.GetValue("content");
string senderName = query.GetValue("sender_name");
TraceLog.Trace("SendEmail.OnSendMailHttpReq httpContextId {0} serverId {1} uid {2} title {3} content {4} senderName {5}", httpContextId, serverId, uid, title, content, senderName);
RepeatedFixedStructString128_10 data = new RepeatedFixedStructString128_10();
data.Add(serverId);
data.Add(uid);
data.Add(title);
data.Add(content);
data.Add(senderName);
HttpApiRootHandler.FillHttpApiDbReq2MessageTaskDistributor(httpApiCmd, httpContextId, ref data);
rsp.IsWaitFor = true;
return 0;
}
//hero舆情系统发送邮件处理
public static int DoSendMail(string httpApiCmd, SSHttpApiDbReq req, DBOperator dbOperator)
{
TraceLog.Trace("SendEmail.DoSendMail 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);
TraceLog.Trace("SendEmail.DoSendMail 1 HttpContextId {0}", req.HttpContextId);
if (req.Data.Count < 5)
{
TraceLog.Error("SendEmail.DoSendMail param error");
builder["code"] = 2;
builder["msg"] = "参数错误";
builder["data"] = null;
}
else
{
MailJsonObj mailContent = new MailJsonObj();
mailContent.contentList = new List<languageContent>();
mailContent.areaNameList = new List<string>();
mailContent.uuid = "hero sdk api";
mailContent.name = req.Data[1].ToString();
languageContent langContent = new languageContent();
langContent.title = req.Data[2].ToString();
langContent.content = req.Data[3].ToString();
langContent.senderName = req.Data[4].ToString();
mailContent.contentList.Add(langContent);
mailContent.isSendToAll = 0;
long start = AppTime.GetTodayStartTime(OperationServerUtils.GetTimeSecond());
long endTime = start + AppTime.SECONDS_ADAY * 2;
DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeSeconds(start);
string dateString = dateTimeOffset.ToString("yyyy-MM-dd HH:mm");
DateTimeOffset end = DateTimeOffset.FromUnixTimeSeconds(endTime);
string endDateString = end.ToString("yyyy-MM-dd HH:mm");
mailContent.timeLimit =dateString+"#"+endDateString ;
int ret = SendMail(builder, mailContent, dbOperator);
if (ret == 0)
{
builder["msg"] = "success";
builder["code"] = ret;
builder["data"] = null;
}
}
}
catch (Exception ex)
{
TraceLog.Error("SendEmail.DoSendMail Error Msg {0}", ex.Message);
}
finally
{
if (m_request != null)
{
m_request.Http.httpResponse.ContentAsUTF8 = builder.ToJson();
m_request.ProcessEnd = true;
}
}
TraceLog.Trace("SendEmail.DoSendMail success httpContextId {0}", req.HttpContextId);
return 0;
}
[RequestMapping("审核邮件",PermissionCode.MAIL_REVIEW, toLog: true)]
public static int OnReviewMailHttpReq(string httpApiCmd, JsonData Jsondata, HttpResponse rsp, HttpRequest request, HttpQueryParams query, uint httpContextId)
{
TraceLog.Trace("SendEmail.OnSendMailHttpReq url {0} ,param count {1} ,httpContextId {2}", request.Url, query.Count, httpContextId);
string uuid = query.GetValue("uuid");
string id = query.GetValue("id");
string status = query.GetValue("status");
RepeatedFixedStructString128_10 data = new RepeatedFixedStructString128_10();
data.Add(uuid);
data.Add(id);
data.Add(status);
HttpApiRootHandler.FillHttpApiDbReq2MessageTaskDistributor(httpApiCmd, httpContextId, ref data);
rsp.IsWaitFor = true;
return 0;
}
public static int DoReviewMail(string httpApiCmd, SSHttpApiDbReq req, DBOperator dbOperator)
{
TraceLog.Trace("SendEmail.DoSendMail 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);
TraceLog.Trace("SendEmail.DoSendMail 1 HttpContextId {0}", req.HttpContextId);
if (req.Data.Count < 3)
{
TraceLog.Error("SendEmail.DoSendMail param error");
builder["code"] = 2;
builder["msg"] = "参数错误";
builder["data"] = null;
}
else
{
var ret = dbOperator.DBReviewEmail(req.Data[0].ToString(), req.Data[1].ToString(),int.Parse(req.Data[2].ToString()) , builder);
if (ret == 0)
{
builder["msg"] = "success";
builder["code"] = ret;
builder["data"] = null;
}
}
}
catch (Exception ex)
{
TraceLog.Error("SendEmail.DoSendMail Error Msg {0}", ex.Message);
}
finally
{
if (m_request != null)
{
m_request.Http.httpResponse.ContentAsUTF8 = builder.ToJson();
m_request.ProcessEnd = true;
}
}
TraceLog.Trace("SendEmail.DoSendMail success httpContextId {0}", req.HttpContextId);
return 0;
}
public static int OnDeleteRefuseMailHttpReq(string httpApiCmd, JsonData Jsondata, HttpResponse rsp, HttpRequest request, HttpQueryParams query, uint httpContextId)
{
TraceLog.Trace("SendEmail.OnDeleteRefuseMailHttpReq url {0} ,param count {1} ,httpContextId {2}", request.Url, query.Count, httpContextId);
string uuid = query.GetValue("uuid");
string id = query.GetValue("id");
RepeatedFixedStructString128_10 data = new RepeatedFixedStructString128_10();
data.Add(uuid);
data.Add(id);
HttpApiRootHandler.FillHttpApiDbReq2MessageTaskDistributor(httpApiCmd, httpContextId, ref data);
rsp.IsWaitFor = true;
return 0;
}
[RequestMapping("删除拒审邮件",PermissionCode.MAIL_DELETE_REFUSE, toLog: true)]
public static int DoDeleteRefuseMail(string httpApiCmd, SSHttpApiDbReq req, DBOperator dbOperator)
{
TraceLog.Trace("SendEmail.DoDeleteRefuseMail 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);
TraceLog.Trace("SendEmail.DoDeleteRefuseMail 1 HttpContextId {0}", req.HttpContextId);
if (req.Data.Count < 2)
{
TraceLog.Error("SendEmail.DoDeleteRefuseMail param error");
builder["code"] = 2;
builder["msg"] = "参数错误";
builder["data"] = null;
}
else
{
var ret = dbOperator.DBDeleteRefuseMail(req.Data[0].ToString(), req.Data[1].ToString(), builder);
if (ret == 0)
{
builder["msg"] = "success";
builder["code"] = ret;
builder["data"] = null;
}
}
}
catch (Exception ex)
{
TraceLog.Error("SendEmail.DoSendMail Error Msg {0}", ex.Message);
}
finally
{
if (m_request != null)
{
m_request.Http.httpResponse.ContentAsUTF8 = builder.ToJson();
m_request.ProcessEnd = true;
}
}
TraceLog.Trace("SendEmail.DoSendMail success httpContextId {0}", req.HttpContextId);
return 0;
}
//rewordStr : type|count#type|count
public static bool CheckItemStr(string rewordStr, GoodsType type, out string errMsg)
{
errMsg = "";
if (rewordStr == "")
{
return true;
}
foreach (string reword in rewordStr.Split("#"))
{
var content = reword.Split("|");
if (content.Length != 2)
{
errMsg = "奖励长度有误!";
return false;
}
if (!OperationCommSvc.CheckItem(type, content[0], content[1].Toint32(0)))
{
errMsg = "奖励有误!类型:" + type+ "Id:" + content[0] + "count:" + content[1].Toint32(0);
return false;
}
}
return true;
}
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]));
}
else if (timeStrList.Length == 2)
{
timeStart = OperationServerUtils.GetTimeStamp(Convert.ToDateTime(timeStrList[0]));
timeEnd = OperationServerUtils.GetTimeStamp(Convert.ToDateTime(timeStrList[1]));
}
}
}
catch (Exception ex)
{
TraceLog.Error("SendEmail.ParseRalm notice 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;
}
}
}