Skip to content

Commit

Permalink
Add BlockAllChatMsgs.
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Feb 24, 2024
1 parent cfe9a7a commit 93127f1
Show file tree
Hide file tree
Showing 15 changed files with 177 additions and 71 deletions.
14 changes: 14 additions & 0 deletions CGALib/gameinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ namespace CGAServiceProtocol
TIMAX_DEFINE_PROTOCOL(LoginGameServer, void(std::string, std::string, int, int, int, int));
TIMAX_DEFINE_PROTOCOL(CreateCharacter, void(cga_create_chara_t));
TIMAX_DEFINE_PROTOCOL(GetGameServerInfo, cga_game_server_info_t());
TIMAX_DEFINE_PROTOCOL(SetBlockAllChatMsg, void(bool));

TIMAX_DEFINE_FORWARD(NotifyServerShutdown, int);
TIMAX_DEFINE_FORWARD(NotifyBattleAction, int);
TIMAX_DEFINE_FORWARD(NotifyBattleMotionPacket, std::string);
Expand Down Expand Up @@ -1465,6 +1467,18 @@ namespace CGA
}
return false;
}
virtual bool SetBlockAllChatMsg(bool bShouldBlock)
{
if (m_connected) {
try {
info = m_client.call(std::chrono::milliseconds(10000), m_endpoint, CGAServiceProtocol::SetBlockAllChatMsg, bShouldBlock);
return true;
}
catch (timax::rpc::exception const &e) { if (e.get_error_code() != timax::rpc::error_code::TIMEOUT) m_connected = false; OutputDebugStringA("rpc exception from " __FUNCTION__); OutputDebugStringA(e.get_error_message().c_str()); }
catch (msgpack::parse_error &e) { OutputDebugStringA("parse exception from " __FUNCTION__); OutputDebugStringA(e.what()); }
}
return false;
}
virtual bool RegisterServerShutdownNotify(const std::function<void(int)> &callback)
{
if (m_connected)
Expand Down
1 change: 1 addition & 0 deletions CGALib/gameinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,7 @@ namespace CGA
virtual bool SendMail(int index, const std::string &msg, bool &result) = 0;
virtual bool SendPetMail(int index, int petid, int itempos, const std::string &msg, bool &result) = 0;
virtual bool GetGameServerInfo(cga_game_server_info_t &info) = 0;
virtual bool SetBlockAllChatMsg(bool bShouldBlock) = 0;

virtual bool RegisterServerShutdownNotify(const std::function<void(int)> &callback) = 0;
virtual bool RegisterBattleActionNotify(const std::function<void(int)> &callback) = 0;
Expand Down
31 changes: 31 additions & 0 deletions CGAssistant/chatform.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "chatform.h"
#include "ui_chatform.h"

#include <QTimer>
#include <QDateTime>

extern CGA::CGAInterface *g_CGAInterface;
Expand All @@ -13,13 +14,25 @@ ChatForm::ChatForm(QWidget *parent) :

m_ChatMaxLines = 100;
ui->textEdit_chat->document()->setMaximumBlockCount(m_ChatMaxLines);

QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(OnAutoChat()));
timer->start(1000);
}

ChatForm::~ChatForm()
{
delete ui;
}

void ChatForm::OnAutoChat()
{
if(g_CGAInterface->IsConnected())
{
g_CGAInterface->SetBlockAllChatMsg(true);
}
}

void ChatForm::on_lineEdit_returnPressed()
{
auto saystring = ui->lineEdit->text().toStdString();
Expand All @@ -36,6 +49,10 @@ void ChatForm::OnNotifyGetPlayerInfo(QSharedPointer<CGA_PlayerInfo_t> player)
m_player = player;
}

void ChatForm::OnNotifyFillChatSettings(bool blockallchatmsgs)
{
ui->checkBox_BlockAllChatMsgs->setChecked(blockallchatmsgs);
}

void ChatForm::OnNotifyFillStaticSettings(int freezetime, int chatmaxlines)
{
Expand Down Expand Up @@ -132,10 +149,24 @@ bool ChatForm::ParseChatSettings(const QJsonValue &val)
if(!val.isObject())
return false;

auto obj = val.toObject();

if(obj.contains("blockallchatmsgs"))
ui->checkBox_BlockAllChatMsgs->setChecked(obj.take("blockallchatmsgs").toBool());

return true;
}

void ChatForm::SaveChatSettings(QJsonObject &obj)
{
obj.insert("blockallchatmsgs", ui->checkBox_BlockAllChatMsgs->isChecked());
}

void ChatForm::on_checkBox_BlockAllChatMsgs_stateChanged(int state)
{
if(g_CGAInterface->IsConnected())
{
g_CGAInterface->SetBlockAllChatMsg(state ? true : false);
}
}

4 changes: 4 additions & 0 deletions CGAssistant/chatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ChatForm : public QWidget
~ChatForm();

public slots:
void OnNotifyFillChatSettings(bool blockallchatmsgs);
void OnNotifyFillStaticSettings(int freezetime, int chatmaxlines);
void OnNotifyGetPlayerInfo(QSharedPointer<CGA_PlayerInfo_t> player);
void OnNotifyChatMsg(int unitid, QString msg, int size, int color);
Expand All @@ -29,6 +30,9 @@ public slots:
private slots:
void on_lineEdit_returnPressed();

void on_checkBox_BlockAllChatMsgs_stateChanged(int state);

void OnAutoChat();
private:
Ui::ChatForm *ui;
QSharedPointer<CGA_PlayerInfo_t> m_player;
Expand Down
36 changes: 31 additions & 5 deletions CGAssistant/chatform.ui
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,37 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_chat">
<property name="text">
<string>[Enter] to send chat</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_chat">
<property name="text">
<string>[Enter] to send chat message</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_BlockAllChatMsgs">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>128</width>
<height>0</height>
</size>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Block all chat messages</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
Expand Down
Binary file modified CGAssistant/lang.qm
Binary file not shown.
10 changes: 9 additions & 1 deletion CGAssistant/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ meet BOSS</source>
</message>
<message>
<source>[Enter] to send chat</source>
<translation>[回车] 发送聊天消息</translation>
<translation type="vanished">[回车] 发送聊天消息</translation>
</message>
<message>
<source>Display Time</source>
Expand Down Expand Up @@ -856,6 +856,14 @@ Chat database will not work properly.</source>
Chat database will not work properly.</source>
<translation type="vanished">创建索引uploadtime失败,消息数据库可能无法正常工作。</translation>
</message>
<message>
<source>[Enter] to send chat message</source>
<translation>[回车] 发送聊天消息</translation>
</message>
<message>
<source>Block all chat messages</source>
<translation type="unfinished">屏蔽所有聊天消息</translation>
</message>
</context>
<context>
<name>ItemForm</name>
Expand Down
10 changes: 7 additions & 3 deletions CGAssistant/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ int main(int argc, char *argv[])

QCommandLineOption chatmaxlines("chatmaxlines", "", "chatmaxlines", "100");

QCommandLineOption blockallchatmsgs("blockallchatmsgs");

QCommandLineParser parser;

parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
Expand Down Expand Up @@ -151,6 +153,7 @@ int main(int argc, char *argv[])
parser.addOption(consolemaxlines);
parser.addOption(scriptfreezeduration);
parser.addOption(chatmaxlines);
parser.addOption(blockallchatmsgs);
parser.process(a);

QTranslator translator;
Expand All @@ -168,7 +171,6 @@ int main(int argc, char *argv[])

MainWindow w;


for(unsigned int qport = 14396; qport < 14396 + 1000; ++qport)
{
if(qserver.listen(QHostAddress::LocalHost, qport, [&w](QHttpRequest* req, QHttpResponse* res) {
Expand Down Expand Up @@ -264,6 +266,8 @@ int main(int argc, char *argv[])

w.show();

w.NotifyFillStaticSettings(parser.value(killfreeze).toInt(), parser.value(chatmaxlines).toInt());

w.NotifyFillAutoLogin(parser.value(gameType).toInt(),
parser.value(loginUser),
parser.value(loginPwd),
Expand Down Expand Up @@ -293,9 +297,9 @@ int main(int argc, char *argv[])
parser.value(consolemaxlines).toInt(),
parser.value(scriptfreezeduration).toInt() );

w.NotifyFillLoadSettings(parser.value(loadsettings));
w.NotifyFillChatSettings(parser.isSet(blockallchatmsgs) ? true : false);

w.NotifyFillStaticSettings(parser.value(killfreeze).toInt(), parser.value(chatmaxlines).toInt());
w.NotifyFillLoadSettings(parser.value(loadsettings));

return a.exec();
}
2 changes: 2 additions & 0 deletions CGAssistant/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ MainWindow::MainWindow(QWidget *parent) :
connect(playerFrom, &PlayerForm::SaveItemTweaker, itemForm, &ItemForm::SaveItemTweaker);
connect(playerFrom, &PlayerForm::SaveBattleSettings, autoBattleForm, &AutoBattleForm::SaveBattleSettings);
connect(playerFrom, &PlayerForm::SaveChatSettings, chatForm, &ChatForm::SaveChatSettings);

connect(this, &MainWindow::NotifyChangeWindow, processFrom, &ProcessForm::OnNotifyChangeWindow);

connect(this, &MainWindow::NotifyFillAutoLogin, accountForm, &AccountForm::OnNotifyFillAutoLogin);
connect(this, &MainWindow::NotifyFillLoadScript, scriptForm, &ScriptForm::OnNotifyFillLoadScript);
connect(this, &MainWindow::NotifyFillLoadSettings, playerFrom, &PlayerForm::OnNotifyFillLoadSettings);
connect(this, &MainWindow::NotifyFillStaticSettings, processWorker, &CProcessWorker::OnNotifyFillStaticSettings);
connect(this, &MainWindow::NotifyFillStaticSettings, chatForm, &ChatForm::OnNotifyFillStaticSettings);
connect(this, &MainWindow::NotifyFillChatSettings, chatForm, &ChatForm::OnNotifyFillChatSettings);

connect(playerWorker, &CPlayerWorker::NotifyGetSkillsInfo, autoBattleForm, &AutoBattleForm::OnNotifyGetSkillsInfo, Qt::ConnectionType::QueuedConnection);
connect(playerWorker, &CPlayerWorker::NotifyGetPetsInfo, autoBattleForm, &AutoBattleForm::OnNotifyGetPetsInfo, Qt::ConnectionType::QueuedConnection);
Expand Down
1 change: 1 addition & 0 deletions CGAssistant/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class MainWindow : public QMainWindow
QString create_chara_points, QString create_chara_elements, QString create_chara_name);
void NotifyFillLoadScript(QString path, int autorestart, bool freezestop, bool injuryprot, bool soulprot, int consolemaxlines, int scriptfreezeduration);
void NotifyFillLoadSettings(QString path);
void NotifyFillChatSettings(bool blockallchatmsgs);
void NotifyFillStaticSettings(int freezetime, int chatmaxlines);
void HttpGetGameProcInfo(QJsonDocument* doc);
void HttpGetSettings(QJsonDocument* doc);
Expand Down
1 change: 0 additions & 1 deletion CGAssistant/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ void CPlayerWorker::OnDownloadMap(int xsize, int ysize)
m_IsDownloadingMap = true;
}


void CPlayerWorker::OnQueueAntiAFKKick()
{
if(!m_bAntiAFKKick)
Expand Down
2 changes: 2 additions & 0 deletions CGAssistant/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ public slots:
void OnSetNoSwitchAnim(int state);
void OnSetGameTextUI(int state);
void OnSetAntiAFKKick(int state);
void OnSetBlockAllChatMsgs(int state);
void OnDownloadMap(int xsize, int ysize);
void OnTabChanged(int tabindex);
void OnSetUseFoodAt(QString str);
Expand Down Expand Up @@ -330,6 +331,7 @@ public slots:
bool m_bHighSpeedBattle;
bool m_bGameTextUI;
bool m_bAntiAFKKick;

QSharedPointer<CGA_PlayerInfo_t> m_player;
QSharedPointer<CGA_PetList_t> m_pets;

Expand Down
Loading

0 comments on commit 93127f1

Please sign in to comment.