added mmokobanmodule
This commit is contained in:
parent
9a94283309
commit
831b76c77f
@ -2,3 +2,4 @@ bin_dir=$$PWD/bin
|
|||||||
lib_dir=$$PWD/lib
|
lib_dir=$$PWD/lib
|
||||||
mmokoban_lib_dir=$$PWD/../mmokoban/lib
|
mmokoban_lib_dir=$$PWD/../mmokoban/lib
|
||||||
include_dir=$$PWD/../mmokoban/src
|
include_dir=$$PWD/../mmokoban/src
|
||||||
|
include_dir=$$PWD/../mmokoban/include
|
||||||
|
@ -31,6 +31,7 @@ unix {
|
|||||||
|
|
||||||
INCLUDEPATH += ../ircbot
|
INCLUDEPATH += ../ircbot
|
||||||
INCLUDEPATH += $$include_dir
|
INCLUDEPATH += $$include_dir
|
||||||
|
INCLUDEPATH += $$sfml_dir
|
||||||
|
|
||||||
SOURCES = main.cpp \
|
SOURCES = main.cpp \
|
||||||
regismodule.cpp \
|
regismodule.cpp \
|
||||||
@ -43,7 +44,8 @@ SOURCES = main.cpp \
|
|||||||
jankenmodule.cpp \
|
jankenmodule.cpp \
|
||||||
janken.cpp \
|
janken.cpp \
|
||||||
rpgmodule.cpp \
|
rpgmodule.cpp \
|
||||||
punishermodule.cpp
|
punishermodule.cpp \
|
||||||
|
mmokobanmodule.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
regismodule.h \
|
regismodule.h \
|
||||||
@ -56,4 +58,5 @@ HEADERS += \
|
|||||||
jankenmodule.h \
|
jankenmodule.h \
|
||||||
janken.h \
|
janken.h \
|
||||||
rpgmodule.h \
|
rpgmodule.h \
|
||||||
punishermodule.h
|
punishermodule.h \
|
||||||
|
mmokobanmodule.h
|
||||||
|
78
app/mmokobanmodule.cpp
Normal file
78
app/mmokobanmodule.cpp
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
#include "mmokobanmodule.h"
|
||||||
|
#include "message.h"
|
||||||
|
#include "user.h"
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
#include <common/mapkoban.h>
|
||||||
|
#include <common/defines.h>
|
||||||
|
#include <serverlib/server.h>
|
||||||
|
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
MMOkobanModule::MMOkobanModule() :
|
||||||
|
m_running(false),
|
||||||
|
m_mmokoban_server(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MMOkobanModule::messageHandler(Message msg)
|
||||||
|
{
|
||||||
|
if(!getUsers()->getFromNick(msg.nick)->isOp())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(msg.args.startsWith("!mmokoban"))
|
||||||
|
{
|
||||||
|
if(msg.args.compare("!mmokoban start") == 0)
|
||||||
|
{
|
||||||
|
if(m_running)
|
||||||
|
answer = say("MMOkoban server is already running.");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
start();
|
||||||
|
answer = say("MMOkoban server starting...");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(msg.args.compare("!mmokoban stop") == 0)
|
||||||
|
{
|
||||||
|
if(!m_running)
|
||||||
|
answer = say("MMOkoban server is already stopped.");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stop();
|
||||||
|
answer = say("MMOkoban server stopping...");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString MMOkobanModule::getName()
|
||||||
|
{
|
||||||
|
return "mmokoban";
|
||||||
|
}
|
||||||
|
|
||||||
|
void MMOkobanModule::start()
|
||||||
|
{
|
||||||
|
m_running = true;
|
||||||
|
|
||||||
|
// launching server
|
||||||
|
m_mmokoban_server = new Server(TCP_PORT);
|
||||||
|
m_mmokoban_server->initMap();
|
||||||
|
|
||||||
|
new std::thread(startUpdateLoop, m_mmokoban_server, m_running);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MMOkobanModule::startUpdateLoop(Server* server, bool &running)
|
||||||
|
{
|
||||||
|
while(running)
|
||||||
|
server->update();
|
||||||
|
delete server;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MMOkobanModule::stop()
|
||||||
|
{
|
||||||
|
m_running = false;
|
||||||
|
m_mmokoban_server = nullptr;
|
||||||
|
}
|
25
app/mmokobanmodule.h
Normal file
25
app/mmokobanmodule.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#ifndef MMOKOBANMODULE_H
|
||||||
|
#define MMOKOBANMODULE_H
|
||||||
|
|
||||||
|
#include <module.h>
|
||||||
|
|
||||||
|
class Server;
|
||||||
|
|
||||||
|
class MMOkobanModule : public Module
|
||||||
|
{
|
||||||
|
bool m_running;
|
||||||
|
Server* m_mmokoban_server;
|
||||||
|
|
||||||
|
void start();
|
||||||
|
void stop();
|
||||||
|
|
||||||
|
static void startUpdateLoop(Server* server, bool &running);
|
||||||
|
|
||||||
|
public:
|
||||||
|
MMOkobanModule();
|
||||||
|
|
||||||
|
bool messageHandler(Message msg);
|
||||||
|
QString getName();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MMOKOBANMODULE_H
|
Loading…
x
Reference in New Issue
Block a user