Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

五轮传奇 #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 51 additions & 61 deletions Dice/Dice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@
#include "CQTools.h"
#include "InitList.h"
#include "GlobalVar.h"
#include "NameStorage.h"
#include "GetRule.h"
#include "DiceMsgSend.h"
#include "CustomMsg.h"
#include"dbManager.h"
#include"nameGetter.h"
#include"l5rDiceManager.h"
/*
TODO:
1. en�ɱ�ɳ��춨
Expand All @@ -57,50 +59,11 @@
using namespace std;
using namespace CQ;

unique_ptr<NameStorage> Name;
//unique_ptr<NameStorage> Name;
unique_ptr<GetRule> RuleGetter;

std::string strip(std::string origin)
{
bool flag = true;
while (flag)
{
flag = false;
if (origin[0] == '!' || origin[0] == '.')
{
origin.erase(origin.begin());
flag = true;
}
else if (origin.substr(0, 2) == "��" || origin.substr(0, 2) == "��")
{
origin.erase(origin.begin());
origin.erase(origin.begin());
flag = true;
}
}
return origin;
}

std::string getName(long long QQ, long long GroupID = 0)
{
if (GroupID)
{
/*Ⱥ*/
if (GroupID < 1000000000)
{
return strip(Name->get(GroupID, QQ).empty()
? (getGroupMemberInfo(GroupID, QQ).GroupNick.empty()
? getStrangerInfo(QQ).nick
: getGroupMemberInfo(GroupID, QQ).GroupNick)
: Name->get(GroupID, QQ));
}
/*������*/
return strip(Name->get(GroupID, QQ).empty() ? getStrangerInfo(QQ).nick : Name->get(GroupID, QQ));
}
/*˽��*/
return strip(getStrangerInfo(QQ).nick);
}

unique_ptr<dbManager> dbCtrl=nullptr;
unique_ptr<nameGetter> nameCtrl = nullptr;
unique_ptr<l5rDiceManager> l5rDiceCtrl = nullptr;
map<long long, RP> JRRP;
map<long long, int> DefaultDice;
map<long long, string> WelcomeMsg;
Expand Down Expand Up @@ -148,7 +111,10 @@ EVE_Enable(__eventEnable)
/*
* ���ƴ洢-�������ȡ
*/
Name = make_unique<NameStorage>(strFileLoc + "Name.dicedb");
//Name = make_unique<NameStorage>(strFileLoc + "Name.dicedb");
dbCtrl = make_unique<dbManager>(strFileLoc);
nameCtrl = make_unique<nameGetter>();
l5rDiceCtrl = make_unique<l5rDiceManager>();
ifstream ifstreamCharacterProp(strFileLoc + "CharacterProp.RDconf");
if (ifstreamCharacterProp)
{
Expand Down Expand Up @@ -345,13 +311,21 @@ EVE_PrivateMsg_EX(__eventPrivateMsg)
while (isspace(eve.message[intMsgCnt]))
intMsgCnt++;
eve.message_block();
const string strNickName = getName(eve.fromQQ);
const string strNickName = nameCtrl->getNickName(eve.fromQQ);
string strLowerMessage = eve.message;
transform(strLowerMessage.begin(), strLowerMessage.end(), strLowerMessage.begin(), tolower);
if (strLowerMessage.substr(intMsgCnt, 4) == "help")
{
AddMsgToQueue(GlobalMsg["strHlpMsg"], eve.fromQQ);
}
else if (strLowerMessage.substr(intMsgCnt, 3) == "lfr")
{
intMsgCnt += 3;
while (isspace(eve.message[intMsgCnt]))
intMsgCnt++;
string reply= l5rDiceCtrl->dice(strNickName, strLowerMessage.substr(intMsgCnt), eve.fromQQ);
AddMsgToQueue(reply, eve.fromQQ);
}
else if (strLowerMessage[intMsgCnt] == 'w')
{
intMsgCnt++;
Expand Down Expand Up @@ -956,7 +930,7 @@ EVE_PrivateMsg_EX(__eventPrivateMsg)
AddMsgToQueue(GlobalMsg["strMEDisabledErr"], eve.fromQQ);
return;
}
string strReply = getName(eve.fromQQ, llGroupID) + eve.message.substr(intMsgCnt);
string strReply = nameCtrl->getNickName(eve.fromQQ, llGroupID) + eve.message.substr(intMsgCnt);
const int intSendRes = sendGroupMsg(llGroupID, strReply);
if (intSendRes < 0)
{
Expand Down Expand Up @@ -1478,7 +1452,7 @@ EVE_GroupMsg_EX(__eventGroupMsg)
while (isspace(eve.message[intMsgCnt]))
intMsgCnt++;
eve.message_block();
const string strNickName = getName(eve.fromQQ, eve.fromGroup);
const string strNickName = nameCtrl->getNickName(eve.fromQQ, eve.fromGroup);
string strLowerMessage = eve.message;
transform(strLowerMessage.begin(), strLowerMessage.end(), strLowerMessage.begin(), tolower);
if (strLowerMessage.substr(intMsgCnt, 3) == "bot")
Expand Down Expand Up @@ -1802,7 +1776,7 @@ EVE_GroupMsg_EX(__eventGroupMsg)
if (strname.empty())
strname = strNickName;
else
strname = strip(strname);
strname = nameCtrl->strip(strname);
RD initdice(strinit);
const int intFirstTimeRes = initdice.Roll();
if (intFirstTimeRes == Value_Err)
Expand Down Expand Up @@ -1866,6 +1840,14 @@ EVE_GroupMsg_EX(__eventGroupMsg)
ilInitList->show(eve.fromGroup, strReply);
AddMsgToQueue(strReply, eve.fromGroup, false);
}
else if (strLowerMessage.substr(intMsgCnt, 3) == "lfr")
{
intMsgCnt += 3;
while (isspace(eve.message[intMsgCnt]))
intMsgCnt++;
string reply= l5rDiceCtrl->dice(strNickName, strLowerMessage.substr(intMsgCnt), eve.fromQQ, eve.fromGroup);
AddMsgToQueue(reply, eve.fromGroup,false);
}
else if (strLowerMessage[intMsgCnt] == 'w')
{
intMsgCnt++;
Expand Down Expand Up @@ -2193,7 +2175,7 @@ EVE_GroupMsg_EX(__eventGroupMsg)
const auto Range = ObserveGroup.equal_range(eve.fromGroup);
for (auto it = Range.first; it != Range.second; ++it)
{
Msg += "\n" + getName(it->second, eve.fromGroup) + "(" + to_string(it->second) + ")";
Msg += "\n" + nameCtrl->getNickName(it->second, eve.fromGroup) + "(" + to_string(it->second) + ")";
}
const string strReply = Msg == "��ǰ���Թ�����:" ? "��ǰ�����Թ���" : Msg;
AddMsgToQueue(strReply, eve.fromGroup, false);
Expand Down Expand Up @@ -2520,13 +2502,13 @@ EVE_GroupMsg_EX(__eventGroupMsg)
}
if (!name.empty())
{
Name->set(eve.fromGroup, eve.fromQQ, name);
const string strReply = "�ѽ�" + strNickName + "�����Ƹ���Ϊ" + strip(name);
nameCtrl->setNickName(name,eve.fromQQ, eve.fromGroup);
const string strReply = "�ѽ�" + strNickName + "�����Ƹ���Ϊ" + nameCtrl->strip(name);
AddMsgToQueue(strReply, eve.fromGroup, false);
}
else
{
if (Name->del(eve.fromGroup, eve.fromQQ))
if (nameCtrl->setNickName(name, eve.fromQQ, eve.fromGroup))
{
const string strReply = "�ѽ�" + strNickName + "������ɾ��";
AddMsgToQueue(strReply, eve.fromGroup, false);
Expand Down Expand Up @@ -3189,7 +3171,7 @@ EVE_DiscussMsg_EX(__eventDiscussMsg)
while (isspace(eve.message[intMsgCnt]))
intMsgCnt++;
eve.message_block();
const string strNickName = getName(eve.fromQQ, eve.fromDiscuss);
const string strNickName = nameCtrl->getNickName(eve.fromQQ, eve.fromDiscuss);
string strLowerMessage = eve.message;
transform(strLowerMessage.begin(), strLowerMessage.end(), strLowerMessage.begin(), tolower);
if (strLowerMessage.substr(intMsgCnt, 3) == "bot")
Expand Down Expand Up @@ -3412,7 +3394,7 @@ EVE_DiscussMsg_EX(__eventDiscussMsg)
if (strname.empty())
strname = strNickName;
else
strname = strip(strname);
strname = nameCtrl->strip(strname);
RD initdice(strinit);
const int intFirstTimeRes = initdice.Roll();
if (intFirstTimeRes == Value_Err)
Expand Down Expand Up @@ -3476,6 +3458,14 @@ EVE_DiscussMsg_EX(__eventDiscussMsg)
ilInitList->show(eve.fromDiscuss, strReply);
AddMsgToQueue(strReply, eve.fromDiscuss, false);
}
else if (strLowerMessage.substr(intMsgCnt, 3) == "lfr")
{
intMsgCnt += 3;
while (isspace(eve.message[intMsgCnt]))
intMsgCnt++;
string reply=l5rDiceCtrl->dice(strNickName, strLowerMessage.substr(intMsgCnt), eve.fromQQ, eve.fromDiscuss);
AddMsgToQueue(reply, eve.fromDiscuss,false);
}
else if (strLowerMessage[intMsgCnt] == 'w')
{
intMsgCnt++;
Expand Down Expand Up @@ -3781,7 +3771,7 @@ EVE_DiscussMsg_EX(__eventDiscussMsg)
const auto Range = ObserveDiscuss.equal_range(eve.fromDiscuss);
for (auto it = Range.first; it != Range.second; ++it)
{
Msg += "\n" + getName(it->second, eve.fromDiscuss) + "(" + to_string(it->second) + ")";
Msg += "\n" + nameCtrl->getNickName(it->second, eve.fromDiscuss) + "(" + to_string(it->second) + ")";
}
const string strReply = Msg == "��ǰ���Թ�����:" ? "��ǰ�����Թ���" : Msg;
AddMsgToQueue(strReply, eve.fromDiscuss, false);
Expand Down Expand Up @@ -4097,13 +4087,13 @@ EVE_DiscussMsg_EX(__eventDiscussMsg)
}
if (!name.empty())
{
Name->set(eve.fromDiscuss, eve.fromQQ, name);
const string strReply = "�ѽ�" + strNickName + "�����Ƹ���Ϊ" + strip(name);
nameCtrl->setNickName(name, eve.fromQQ, eve.fromDiscuss);
const string strReply = "�ѽ�" + strNickName + "�����Ƹ���Ϊ" + nameCtrl->strip(name);
AddMsgToQueue(strReply, eve.fromDiscuss, false);
}
else
{
if (Name->del(eve.fromDiscuss, eve.fromQQ))
if (nameCtrl->setNickName(name, eve.fromQQ, eve.fromDiscuss))
{
const string strReply = "�ѽ�" + strNickName + "������ɾ��";
AddMsgToQueue(strReply, eve.fromDiscuss, false);
Expand Down Expand Up @@ -4769,7 +4759,7 @@ EVE_Disable(__eventDisable)
Enabled = false;
ilInitList.reset();
RuleGetter.reset();
Name.reset();
// Name.reset();
ofstream ofstreamDisabledGroup(strFileLoc + "DisabledGroup.RDconf", ios::out | ios::trunc);
for (auto it = DisabledGroup.begin(); it != DisabledGroup.end(); ++it)
{
Expand Down Expand Up @@ -4907,7 +4897,7 @@ EVE_Exit(__eventExit)
return 0;
ilInitList.reset();
RuleGetter.reset();
Name.reset();
// Name.reset();
ofstream ofstreamDisabledGroup(strFileLoc + "DisabledGroup.RDconf", ios::out | ios::trunc);
for (auto it = DisabledGroup.begin(); it != DisabledGroup.end(); ++it)
{
Expand Down
21 changes: 16 additions & 5 deletions Dice/Dice.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,35 @@
<ProjectGuid>{BA051175-B8E8-4104-9DD9-B9E225738C42}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Dice</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
<ProjectName>com.w4123.dice</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down Expand Up @@ -92,6 +92,7 @@
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<Linkage-AWSSDKCPP-Core>static</Linkage-AWSSDKCPP-Core>
<Linkage-AWSSDKCPP-DynamoDB>static</Linkage-AWSSDKCPP-DynamoDB>
<IncludePath>$(ProjectDir)sqlite3;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
Expand Down Expand Up @@ -130,6 +131,7 @@
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
<ForceSymbolReferences>%(ForceSymbolReferences)</ForceSymbolReferences>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>MSVCRT;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
Expand Down Expand Up @@ -204,13 +206,17 @@
<ClCompile Include="..\CQSDKCPP\CQTools.cpp" />
<ClCompile Include="..\CQSDKCPP\Unpack.cpp" />
<ClCompile Include="CustomMsg.cpp" />
<ClCompile Include="dbManager.cpp" />
<ClCompile Include="Dice.cpp" />
<ClCompile Include="DiceMsgSend.cpp" />
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="EncodingConvert.cpp" />
<ClCompile Include="GetRule.cpp" />
<ClCompile Include="GlobalVar.cpp" />
<ClCompile Include="InitList.cpp" />
<ClCompile Include="l5rDice.cpp" />
<ClCompile Include="l5rDiceManager.cpp" />
<ClCompile Include="nameGetter.cpp" />
<ClCompile Include="NameStorage.cpp" />
<ClCompile Include="RD.cpp" />
<ClCompile Include="StorageBase.cpp" />
Expand Down Expand Up @@ -239,19 +245,24 @@
<ClInclude Include="..\CQSDK\Unpack.h" />
<ClInclude Include="APPINFO.h" />
<ClInclude Include="CustomMsg.h" />
<ClInclude Include="dbManager.h" />
<ClInclude Include="DiceMsgSend.h" />
<ClInclude Include="EncodingConvert.h" />
<ClInclude Include="GetRule.h" />
<ClInclude Include="GlobalVar.h" />
<ClInclude Include="InitList.h" />
<ClInclude Include="json.hpp" />
<ClInclude Include="l5rDice.h" />
<ClInclude Include="l5rDiceManager.h" />
<ClInclude Include="nameGetter.h" />
<ClInclude Include="NameStorage.h" />
<ClInclude Include="RD.h" />
<ClInclude Include="RDConstant.h" />
<ClInclude Include="StorageBase.h" />
</ItemGroup>
<ItemGroup>
<Library Include="CQP.lib" />
<Library Include="sqlite3\sqlite3.lib" />
</ItemGroup>
<ItemGroup>
<None Include="com.w4123.dice.json" />
Expand Down
Loading