parent
3522ea81b6
commit
fde7d41e19
|
@ -20,6 +20,31 @@ Flickable {
|
||||||
width: parent.width - 40
|
width: parent.width - 40
|
||||||
x: 20
|
x: 20
|
||||||
|
|
||||||
|
// TODO: player details
|
||||||
|
Text {
|
||||||
|
id: screenName
|
||||||
|
font.pixelSize: 18
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
id: playerGameData
|
||||||
|
Layout.fillWidth: true
|
||||||
|
font.pixelSize: 18
|
||||||
|
}
|
||||||
|
|
||||||
|
TextEdit {
|
||||||
|
id: skillDesc
|
||||||
|
|
||||||
|
Layout.fillWidth: true
|
||||||
|
font.pixelSize: 18
|
||||||
|
|
||||||
|
readOnly: true
|
||||||
|
selectByKeyboard: true
|
||||||
|
selectByMouse: false
|
||||||
|
wrapMode: TextEdit.WordWrap
|
||||||
|
textFormat: TextEdit.RichText
|
||||||
|
}
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
Button {
|
Button {
|
||||||
text: Backend.translate("Give Flower")
|
text: Backend.translate("Give Flower")
|
||||||
|
@ -62,7 +87,22 @@ Flickable {
|
||||||
root.finish();
|
root.finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
Button {
|
||||||
|
text: config.blockedUsers.indexOf(screenName.text) === -1 ? Backend.translate("Block Chatter") : Backend.translate("Unblock Chatter")
|
||||||
|
enabled: pid !== Self.id && pid > 0
|
||||||
|
onClicked: {
|
||||||
|
const idx = config.blockedUsers.indexOf(screenName.text);
|
||||||
|
if (idx === -1) {
|
||||||
|
config.blockedUsers.push(screenName.text);
|
||||||
|
} else {
|
||||||
|
config.blockedUsers.splice(idx, 1);
|
||||||
|
}
|
||||||
|
config.blockedUsersChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
Button {
|
Button {
|
||||||
text: Backend.translate("Kick From Room")
|
text: Backend.translate("Kick From Room")
|
||||||
visible: !roomScene.isStarted && roomScene.isOwner
|
visible: !roomScene.isStarted && roomScene.isOwner
|
||||||
|
@ -73,34 +113,6 @@ Flickable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: player details
|
|
||||||
RowLayout {
|
|
||||||
spacing: 16
|
|
||||||
Text {
|
|
||||||
id: screenName
|
|
||||||
font.pixelSize: 18
|
|
||||||
}
|
|
||||||
|
|
||||||
Text {
|
|
||||||
id: playerGameData
|
|
||||||
Layout.fillWidth: true
|
|
||||||
font.pixelSize: 18
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TextEdit {
|
|
||||||
id: skillDesc
|
|
||||||
|
|
||||||
Layout.fillWidth: true
|
|
||||||
font.pixelSize: 18
|
|
||||||
|
|
||||||
readOnly: true
|
|
||||||
selectByKeyboard: true
|
|
||||||
selectByMouse: false
|
|
||||||
wrapMode: TextEdit.WordWrap
|
|
||||||
textFormat: TextEdit.RichText
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function givePresent(p) {
|
function givePresent(p) {
|
||||||
|
@ -132,7 +144,8 @@ Flickable {
|
||||||
const run = gamedata[2];
|
const run = gamedata[2];
|
||||||
const winRate = (win / total) * 100;
|
const winRate = (win / total) * 100;
|
||||||
const runRate = (run / total) * 100;
|
const runRate = (run / total) * 100;
|
||||||
playerGameData.text = total === 0 ? Backend.translate("Newbie") : "<br/>" + Backend.translate("Win=%1 Run=%2 Total=%3").arg(winRate.toFixed(2))
|
playerGameData.text = total === 0 ? Backend.translate("Newbie") :
|
||||||
|
Backend.translate("Win=%1 Run=%2 Total=%3").arg(winRate.toFixed(2))
|
||||||
.arg(runRate.toFixed(2)).arg(total);
|
.arg(runRate.toFixed(2)).arg(total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ QtObject {
|
||||||
property int roomTimeout: 0
|
property int roomTimeout: 0
|
||||||
property bool enableFreeAssign: false
|
property bool enableFreeAssign: false
|
||||||
property bool observing: false
|
property bool observing: false
|
||||||
|
property var blockedUsers: []
|
||||||
|
|
||||||
function loadConf() {
|
function loadConf() {
|
||||||
conf = JSON.parse(Backend.loadConf());
|
conf = JSON.parse(Backend.loadConf());
|
||||||
|
|
|
@ -142,6 +142,10 @@ callbacks["Chat"] = (jsonData) => {
|
||||||
const time = data.time;
|
const time = data.time;
|
||||||
const msg = data.msg;
|
const msg = data.msg;
|
||||||
|
|
||||||
|
if (config.blockedUsers.indexOf(userName) !== -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (general === "")
|
if (general === "")
|
||||||
current.addToChat(pid, data, `[${time}] ${userName}: ${msg}`);
|
current.addToChat(pid, data, `[${time}] ${userName}: ${msg}`);
|
||||||
else
|
else
|
||||||
|
|
|
@ -150,6 +150,7 @@ Rectangle {
|
||||||
PropertyAction { target: splash; property: "loading"; value: false }
|
PropertyAction { target: splash; property: "loading"; value: false }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
Text {
|
Text {
|
||||||
text: "常用联机IP:175.178.66.93\n新月杀联机交流群:531553435"
|
text: "常用联机IP:175.178.66.93\n新月杀联机交流群:531553435"
|
||||||
font.pixelSize: 20
|
font.pixelSize: 20
|
||||||
|
@ -159,6 +160,7 @@ Rectangle {
|
||||||
anchors.rightMargin: 20
|
anchors.rightMargin: 20
|
||||||
horizontalAlignment: Text.AlignRight
|
horizontalAlignment: Text.AlignRight
|
||||||
}
|
}
|
||||||
|
**/
|
||||||
|
|
||||||
//--------------------Disappear--------------
|
//--------------------Disappear--------------
|
||||||
Behavior on opacity {
|
Behavior on opacity {
|
||||||
|
|
|
@ -251,6 +251,10 @@
|
||||||
<source>you have been banned!</source>
|
<source>you have been banned!</source>
|
||||||
<translation>你已经被该服务器封禁!</translation>
|
<translation>你已经被该服务器封禁!</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>you have been temporarily banned!</source>
|
||||||
|
<translation>由于逃跑或者其他不正当行为,你已经被暂时封禁!</translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
|
|
||||||
<context>
|
<context>
|
||||||
|
|
|
@ -54,6 +54,8 @@ Fk:loadTranslationTable{
|
||||||
["Give Egg"] = "砸蛋",
|
["Give Egg"] = "砸蛋",
|
||||||
["Give Wine"] = "酒杯",
|
["Give Wine"] = "酒杯",
|
||||||
["Give Shoe"] = "拖鞋",
|
["Give Shoe"] = "拖鞋",
|
||||||
|
["Block Chatter"] = "屏蔽发言",
|
||||||
|
["Unblock Chatter"] = "解除屏蔽",
|
||||||
["Kick From Room"] = "踢出房间",
|
["Kick From Room"] = "踢出房间",
|
||||||
["Newbie"] = "新手保护ing",
|
["Newbie"] = "新手保护ing",
|
||||||
["Win=%1 Run=%2 Total=%3"] = "胜率%1% 逃率%2% 总场次%3",
|
["Win=%1 Run=%2 Total=%3"] = "胜率%1% 逃率%2% 总场次%3",
|
||||||
|
|
|
@ -315,7 +315,10 @@ void Router::handlePacket(const QByteArray &rawPacket) {
|
||||||
ServerPlayer *player = qobject_cast<ServerPlayer *>(parent());
|
ServerPlayer *player = qobject_cast<ServerPlayer *>(parent());
|
||||||
player->setThinking(false);
|
player->setThinking(false);
|
||||||
// qDebug() << "wake up!";
|
// qDebug() << "wake up!";
|
||||||
player->getRoom()->getThread()->wakeUp();
|
auto room = player->getRoom();
|
||||||
|
if (room->getThread()) {
|
||||||
|
room->getThread()->wakeUp();
|
||||||
|
}
|
||||||
|
|
||||||
if (requestId != this->expectedReplyId)
|
if (requestId != this->expectedReplyId)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <qjsonarray.h>
|
#include <qjsonarray.h>
|
||||||
#include <qjsondocument.h>
|
#include <qjsondocument.h>
|
||||||
|
|
||||||
|
#include "client_socket.h"
|
||||||
#include "roomthread.h"
|
#include "roomthread.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "serverplayer.h"
|
#include "serverplayer.h"
|
||||||
|
@ -265,6 +266,11 @@ void Room::removePlayer(ServerPlayer *player) {
|
||||||
// 原先的跑路机器人会在游戏结束后自动销毁掉
|
// 原先的跑路机器人会在游戏结束后自动销毁掉
|
||||||
server->addPlayer(runner);
|
server->addPlayer(runner);
|
||||||
|
|
||||||
|
// 如果走小道的人不是单机启动玩家 那么直接ban
|
||||||
|
if (!runner->getSocket()->peerAddress().contains("127.0.0.1")) {
|
||||||
|
server->temporarilyBan(runner->getId());
|
||||||
|
}
|
||||||
|
|
||||||
m_thread->wakeUp();
|
m_thread->wakeUp();
|
||||||
|
|
||||||
// 发出信号,让大厅添加这个人
|
// 发出信号,让大厅添加这个人
|
||||||
|
|
|
@ -86,7 +86,7 @@ bool RoomThread::hasRequest() {
|
||||||
|
|
||||||
void RoomThread::trySleep(int ms) {
|
void RoomThread::trySleep(int ms) {
|
||||||
if (sema_wake.available() > 0) {
|
if (sema_wake.available() > 0) {
|
||||||
sema_wake.acquire(sema_wake.available());
|
sema_wake.tryAcquire(sema_wake.available(), ms);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -210,13 +210,22 @@ void Server::processNewConnection(ClientSocket *client) {
|
||||||
qInfo() << addr << "connected";
|
qInfo() << addr << "connected";
|
||||||
auto result = SelectFromDatabase(
|
auto result = SelectFromDatabase(
|
||||||
db, QString("SELECT * FROM banip WHERE ip='%1';").arg(addr));
|
db, QString("SELECT * FROM banip WHERE ip='%1';").arg(addr));
|
||||||
|
|
||||||
|
auto errmsg = QString();
|
||||||
|
|
||||||
if (!result.isEmpty()) {
|
if (!result.isEmpty()) {
|
||||||
|
errmsg = "you have been banned!";
|
||||||
|
} else if (temp_banlist.contains(addr)) {
|
||||||
|
errmsg = "you have been temporarily banned!";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!errmsg.isEmpty()) {
|
||||||
QJsonArray body;
|
QJsonArray body;
|
||||||
body << -2;
|
body << -2;
|
||||||
body << (Router::TYPE_NOTIFICATION | Router::SRC_SERVER |
|
body << (Router::TYPE_NOTIFICATION | Router::SRC_SERVER |
|
||||||
Router::DEST_CLIENT);
|
Router::DEST_CLIENT);
|
||||||
body << "ErrorMsg";
|
body << "ErrorMsg";
|
||||||
body << "you have been banned!";
|
body << errmsg;
|
||||||
client->send(JsonArray2Bytes(body));
|
client->send(JsonArray2Bytes(body));
|
||||||
qInfo() << "Refused banned IP:" << addr;
|
qInfo() << "Refused banned IP:" << addr;
|
||||||
client->disconnectFromHost();
|
client->disconnectFromHost();
|
||||||
|
@ -552,15 +561,21 @@ RSA *Server::initServerRSA() {
|
||||||
return rsa;
|
return rsa;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define SET_DEFAULT_CONFIG(k, v) do {\
|
||||||
|
if (config.value(k).isUndefined()) { \
|
||||||
|
config[k] = (v); \
|
||||||
|
} } while (0)
|
||||||
|
|
||||||
void Server::readConfig() {
|
void Server::readConfig() {
|
||||||
QFile file("freekill.server.config.json");
|
QFile file("freekill.server.config.json");
|
||||||
if (!file.open(QIODevice::ReadOnly)) {
|
QByteArray json = "{}";
|
||||||
return;
|
if (file.open(QIODevice::ReadOnly)) {
|
||||||
|
json = file.readAll();
|
||||||
}
|
}
|
||||||
auto json = file.readAll();
|
|
||||||
config = QJsonDocument::fromJson(json).object();
|
config = QJsonDocument::fromJson(json).object();
|
||||||
|
|
||||||
// defaults
|
// defaults
|
||||||
|
SET_DEFAULT_CONFIG("tempBanTime", 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonValue Server::getConfig(const QString &key) { return config.value(key); }
|
QJsonValue Server::getConfig(const QString &key) { return config.value(key); }
|
||||||
|
@ -578,3 +593,20 @@ bool Server::checkBanWord(const QString &str) {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Server::temporarilyBan(int playerId) {
|
||||||
|
auto player = findPlayer(playerId);
|
||||||
|
if (!player) return;
|
||||||
|
|
||||||
|
auto socket = player->getSocket();
|
||||||
|
if (!socket) return;
|
||||||
|
|
||||||
|
auto addr = socket->peerAddress();
|
||||||
|
temp_banlist.append(addr);
|
||||||
|
|
||||||
|
auto time = getConfig("tempBanTime").toInt();
|
||||||
|
QTimer::singleShot(time * 60000, this, [=]() {
|
||||||
|
temp_banlist.removeOne(addr);
|
||||||
|
});
|
||||||
|
emit player->kicked();
|
||||||
|
}
|
||||||
|
|
|
@ -44,6 +44,8 @@ public:
|
||||||
|
|
||||||
QJsonValue getConfig(const QString &command);
|
QJsonValue getConfig(const QString &command);
|
||||||
bool checkBanWord(const QString &str);
|
bool checkBanWord(const QString &str);
|
||||||
|
void temporarilyBan(int playerId);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void roomCreated(Room *room);
|
void roomCreated(Room *room);
|
||||||
void playerAdded(ServerPlayer *player);
|
void playerAdded(ServerPlayer *player);
|
||||||
|
@ -67,6 +69,7 @@ private:
|
||||||
int nextRoomId;
|
int nextRoomId;
|
||||||
friend Room::Room(RoomThread *m_thread);
|
friend Room::Room(RoomThread *m_thread);
|
||||||
QHash<int, ServerPlayer *> players;
|
QHash<int, ServerPlayer *> players;
|
||||||
|
QList<QString> temp_banlist;
|
||||||
|
|
||||||
RSA *rsa;
|
RSA *rsa;
|
||||||
QString public_key;
|
QString public_key;
|
||||||
|
|
|
@ -110,8 +110,8 @@ void QmlBackend::joinServer(QString address) {
|
||||||
void QmlBackend::quitLobby(bool close) {
|
void QmlBackend::quitLobby(bool close) {
|
||||||
if (ClientInstance)
|
if (ClientInstance)
|
||||||
delete ClientInstance;
|
delete ClientInstance;
|
||||||
if (ServerInstance && close)
|
// if (ServerInstance && close)
|
||||||
ServerInstance->deleteLater();
|
// ServerInstance->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlBackend::emitNotifyUI(const QString &command, const QString &jsonData) {
|
void QmlBackend::emitNotifyUI(const QString &command, const QString &jsonData) {
|
||||||
|
|
Loading…
Reference in New Issue