summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBlue <bluesansdouze@gmail.com>2009-05-01 21:37:34 +0200
committerJared Adams <jaxad0127@gmail.com>2009-05-01 14:25:35 -0600
commit7db58a9a70d8d2799525cf9eee94b826eaea198b (patch)
tree98e90cd9a9274b1def35512dd7d67bbf7fb4b295 /src
parent43e99491a76bb85faf60c004e84b6c2b14cf41e7 (diff)
downloadmanaserv-7db58a9a70d8d2799525cf9eee94b826eaea198b.tar.gz
manaserv-7db58a9a70d8d2799525cf9eee94b826eaea198b.tar.bz2
manaserv-7db58a9a70d8d2799525cf9eee94b826eaea198b.tar.xz
manaserv-7db58a9a70d8d2799525cf9eee94b826eaea198b.zip
Mysql backend, lua and NPC handler
Fix for mysql backend (again) Lua modification for integer and string ask with NPC, and closing fix.
Diffstat (limited to 'src')
-rw-r--r--src/dal/mysqldataprovider.cpp16
-rw-r--r--src/defines.h5
-rw-r--r--src/game-server/gamehandler.cpp10
-rw-r--r--src/game-server/npc.cpp4
-rw-r--r--src/scripting/lua.cpp47
5 files changed, 74 insertions, 8 deletions
diff --git a/src/dal/mysqldataprovider.cpp b/src/dal/mysqldataprovider.cpp
index e7111a59..008ffda2 100644
--- a/src/dal/mysqldataprovider.cpp
+++ b/src/dal/mysqldataprovider.cpp
@@ -113,14 +113,14 @@ MySqlDataProvider::connect()
<< "' as user, and '" << dbName << "' as database.");
// actually establish the connection.
- if (!mysql_real_connect(mDb, // handle to the connection
- hostname.c_str(), // hostname
- username.c_str(), // username
- password.c_str(), // password
- dbName.c_str(), // database name
- tcpPort, // tcp port
- NULL, // socket, currently not used
- 0)) // client flags
+ if (!mysql_real_connect(mDb, // handle to the connection
+ hostname.c_str(), // hostname
+ username.c_str(), // username
+ password.c_str(), // password
+ dbName.c_str(), // database name
+ tcpPort, // tcp port
+ NULL, // socket, currently not used
+ CLIENT_FOUND_ROWS)) // client flags
{
std::string msg(mysql_error(mDb));
mysql_close(mDb);
diff --git a/src/defines.h b/src/defines.h
index 57860edd..19909b33 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -163,9 +163,14 @@ enum {
GPMSG_NPC_SELL = 0x02B6, // W being id, { W item id, W amount, W cost }*
PGMSG_NPC_BUYSELL = 0x02B7, // W item id, W amount
GPMSG_NPC_ERROR = 0x02B8, // B error
+ GPMSG_NPC_CLOSE = 0x02B9, // W being id
GPMSG_NPC_POST = 0x02D0, // W being id
PGMSG_NPC_POST_SEND = 0x02D1, // W being id, { S name, S text, W item id }
GPMSG_NPC_POST_GET = 0x02D2, // W being id, S name, S text, W item id
+ PGMSG_NPC_NUMBER = 0x02D3, // W being id, L number
+ PGMSG_NPC_STRING = 0x02D4, // W being id, S string
+ GPMSG_NPC_NUMBER = 0x02D5, // W being id
+ GPMSG_NPC_STRING = 0x02D6, // W being id
PGMSG_TRADE_REQUEST = 0x02C0, // W being id
GPMSG_TRADE_REQUEST = 0x02C1, // W being id
GPMSG_TRADE_START = 0x02C2, // -
diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp
index 42e9ce7a..5d46010c 100644
--- a/src/game-server/gamehandler.cpp
+++ b/src/game-server/gamehandler.cpp
@@ -205,6 +205,8 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message)
case PGMSG_NPC_TALK:
case PGMSG_NPC_TALK_NEXT:
case PGMSG_NPC_SELECT:
+ case PGMSG_NPC_NUMBER:
+ case PGMSG_NPC_STRING:
{
int id = message.readShort();
Actor *o = findActorNear(computer.character, id);
@@ -219,6 +221,14 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message)
{
q->select(computer.character, message.readByte());
}
+ else if(message.getId() == PGMSG_NPC_NUMBER)
+ {
+
+ }
+ else if(message.getId() == PGMSG_NPC_STRING)
+ {
+
+ }
else
{
q->prompt(computer.character, message.getId() == PGMSG_NPC_TALK);
diff --git a/src/game-server/npc.cpp b/src/game-server/npc.cpp
index e45692b6..60ba456d 100644
--- a/src/game-server/npc.cpp
+++ b/src/game-server/npc.cpp
@@ -63,3 +63,7 @@ void NPC::select(Character *ch, int v)
mScript->execute();
}
+/*void NPC::integerRecepted()
+{
+
+}*/
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index c2c6baf9..68cdeca1 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -111,6 +111,39 @@ static int npc_choice(lua_State *s)
}
/**
+ * Callback for sending a NPC_INTEGER.
+ * tmw.npc_integer(npc, character, msg, min, max, defaut)
+ */
+static int npc_ask_integer(lua_State *s)
+{
+ LOG_WARN("Appel de NPC Integer ! ");
+
+ NPC *p = getNPC(s, 1);
+ Character *q = getCharacter(s, 2);
+ if (!p || !q)
+ {
+ raiseScriptError(s, "npc_integer called with incorrect parameters.");
+ return 0;
+ }
+ MessageOut msg(GPMSG_NPC_NUMBER);
+ msg.writeShort(p->getPublicID());
+
+ int min = lua_tointeger(s, 3);
+ int max = lua_tointeger(s, 4);
+ int default_num = min;
+ if(lua_gettop(s) == 5) default_num = lua_tointeger(s, 5);
+
+ msg.writeLong(min);
+ msg.writeLong(max);
+ msg.writeLong(default_num);
+ gameHandler->sendTo(q, msg);
+
+ LOG_WARN("MSG SENT ! " << min << " ; " << max << " ; " << default_num << " ; ");
+
+ return 0;
+}
+
+/**
* Callback for creating a NPC on the current map with the current script.
* tmw.npc_create(string name, int id, int x, int y): npc
*/
@@ -141,6 +174,18 @@ static int npc_create(lua_State *s)
return 1;
}
+static int npc_end(lua_State *s)
+{
+ LOG_WARN("Conversation's over !");
+
+ NPC *p = getNPC(s, 1);
+ Character *q = getCharacter(s, 2);
+
+ MessageOut msg(GPMSG_NPC_CLOSE);
+ msg.writeShort(p->getPublicID());
+ gameHandler->sendTo(q, msg);
+}
+
/**
* Callback for sending a NPC_POST.
* tmw.npc_post(npc, character)
@@ -1165,6 +1210,8 @@ LuaScript::LuaScript():
{ "test_tableget", &test_tableget },
{ "get_map_id", &get_map_id },
{ "item_drop", &item_drop },
+ { "npc_ask_integer", &npc_ask_integer },
+ { "npc_end", &npc_end },
{ NULL, NULL }
};
luaL_register(mState, "tmw", callbacks);