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.

184 lines
5.7 KiB

1 month ago
using System.Collections.Generic;
using System.IO;
using Sog;
using ProtoCSStruct;
using Sog.IO;
using System.Linq;
namespace Mail
{
public partial class GmCmdSvc : BaseReloadableService
{
public override int GetServiceType()
{
return MailServiceType.GmCmdSvc;
}
//销毁的时候清空指令注册
public override void Dispose()
{
GmCommandMgr.Instance.ClearAll();
}
//构造的时候注册所有指令
public GmCmdSvc()
{
RegisterAllGmCmd();
}
private void RegisterAllGmCmd()
{
//GmCommandMgr.Instance.Register("SendMail", "SendMail -t10001 money diamond title | content; send one mail to user 10001", this.SendMail);
//GmCommandMgr.Instance.Register("SendMailReadFile", "SendMailReadFile filename chip diamond itemid itemcount -t10001", this.SendMailReadFile);
GmCommandMgr.Instance.Register("DeleteMail", "DeleteMail mailid -t10001; delete mailid mail from user 10001", this.DeleteMail);
GmCommandMgr.Instance.Register("StopServer", "StopServer afterminute", this.StopServer);
GmCommandMgr.Instance.Register("OnlinePlayer", "log print Online player", this.OnlinePlayer);
GmCommandMgr.Instance.Register("PrintMailfdb", "PrintMailfdb", this.PrintMailfdb);
}
public int SendMail(long userid, string[] cmdParams)
{
if (userid == 0)
{
TraceLog.Error("GmCmdSvc.SendMail invalid userid param {0}");
return -1;
}
if (cmdParams.Length < 5)
{
TraceLog.Error("GmCmdSvc.SendMail invalid param,need money diamond title diamond");
return -1;
}
uint chip = 0;
int diamond = 0;
uint.TryParse(cmdParams[0], out chip);
int.TryParse(cmdParams[1], out diamond);
string title = "";
string content = "";
int i = 2;
for (; i < cmdParams.Length; i++)
{
if (cmdParams[i] == "|")
{
i++;
break;
}
if (title != "")
{
title += " ";
}
title += cmdParams[i];
}
title = title.Replace("\\n", "\n");
for (; i < cmdParams.Length; i++)
{
if (content != "")
{
content += " ";
}
content += cmdParams[i];
}
content = content.Replace("\\n", "\n");
DBMail sendMail = new DBMail();
sendMail.Uid = userid;
sendMail.Title.SetString(title);
sendMail.Content.SetString(content);
if (chip > 0)
{
//var currency = new IDValue64() { Id = (long)CurrencyType.Chip, Value = chip };
//sendMail.AddCurrency.Add(ref currency);
}
if (diamond > 0)
{
//var currency = new IDValue64() { Id = (long)CurrencyType.Diamond, Value = diamond };
//sendMail.AddCurrency.Add(ref currency);
}
sendMail.MailType = 0;
MailSendWithRule.SendMail(ref sendMail);
return 0;
}
public int DeleteMail(long userid, string[] cmdParams)
{
if (cmdParams.Length < 1)
{
TraceLog.Error("GmCmdSvc.DeleteMail invalid param,need mailid");
return -1;
}
uint mailID = 0;
uint.TryParse(cmdParams[0], out mailID);
if (mailID == 0)
{
TraceLog.Error("GmCmdSvc.DeleteMail invalid mailid param {0}", cmdParams[0]);
return -2;
}
DBMail mail = new DBMail();
mail.MailID = mailID;
mail.Uid = userid;
MailSendWithRule.SendMail(ref mail, MailOpType.Delete);
return 0;
}
public int StopServer(long userid, string[] cmdParams)
{
if (cmdParams.Length != 1)
{
TraceLog.Error("GmCmdSvc.StopServer invalid param,need minute");
return -1;
}
int minute = 0;
int.TryParse(cmdParams[0], out minute);
//StopServerSvc.StartStopServer(minute);
TraceLog.Debug("GmCmdSvc.StopServer, server will stop after {0} minute", minute);
return 0;
}
public int OnlinePlayer(long userid, string[] cmdParams)
{
int onlineN = MailServerUtils.GetMailServerData().m_playerTable.Count(p => p.Value.IsOnline == true);
TraceLog.Trace("GmCmdSvc.OnlinePlayer Num {0}", onlineN);
return 0;
}
public int PrintMailfdb(long userid, string[] cmdParams)
{
ref var mailFdb = ref MailServerUtils.GetMailServerData().m_mailWithRule;
TraceLog.Trace("GmCmdSvc.PrintMailfdb opsvr ver {0} mail list num {1}"
, mailFdb.OpSvrToMailSeq, mailFdb.MailRecord.Count);
for (int i = 0; i < mailFdb.MailRecord.Count; i++)
{
ref var mail = ref mailFdb.MailRecord[i];
TraceLog.Trace("GmCmdSvc.PrintMailfdb i {0} mailId {1} title {2} lang {3} uid {4} sendMailRule {5} endTime {6} versionSeq {7}"
, i, mail.Mail.MailID, mail.Mail.Title.GetString(), mail.Mail.Language.GetString()
, mail.Mail.Uid, mail.SendMailRuleType, mail.EndTime, mail.VersionSeq);
}
return 0;
}
}
}