luacomponent.cpp

Sat, 27 Mar 2010 17:43:08 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Sat, 27 Mar 2010 17:43:08 +0000
changeset 0
cc66ad6b0d75
permissions
-rw-r--r--

Initial commit (importing from old SVN repo which got lost)

0
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 // g++ -Wall -O2 -pipe -march=i686 "%f" /usr/local/lib/libgloox.so /usr/lib/liblua5.1.so
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 #include </usr/local/include/gloox/gloox.h>
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 #include </usr/local/include/gloox/client.h>
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 #include </usr/local/include/gloox/clientbase.h>
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 #include </usr/local/include/gloox/messagehandler.h>
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 #include </usr/local/include/gloox/tag.h>
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 #include </usr/local/include/gloox/stanza.h>
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 #include </usr/local/include/gloox/connectionlistener.h>
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 #include </usr/local/include/gloox/presencehandler.h>
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 #include </usr/local/include/gloox/component.h>
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 extern "C" {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 #include <lua.h>
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 #include <lualib.h>
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 #include <lauxlib.h>
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 using namespace gloox;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 lua_State *L = NULL;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 lua_State *calcL = NULL;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 char BotName[26];
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 class Bot* theBot = NULL;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 int lcJoinMUC(lua_State* L);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 int lcSleep(lua_State* L);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 int lcMemUsage(lua_State* L);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 int lcSendPresence(lua_State* L);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 int lcSendMessage(lua_State* L);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 class Bot : public MessageHandler, ConnectionListener , PresenceHandler, LogHandler
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 public:
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 Bot()
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 ::theBot = this;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 lua_getglobal(L, "BotPass");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 if(!lua_isstring(L, -1))
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 printf("Please, in the body of the script, set BotJID, BotPass, and BotName!\n");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 return;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 // JID jid( lua_tostring(L, -3) );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 j = new Component ( "jabber:component:accept", "localhost", "xmoo", "secret", 5347);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 j->registerConnectionListener( this );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 j->registerMessageHandler( this );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 j->registerPresenceHandler( this );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 j->logInstance().registerLogHandler( LogLevelDebug, LogAreaAll, this );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 // j->setInitialPriority( 5 );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 // j->setAutoPresence( true );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 printf("Connecting...\n");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 j->connect();
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 virtual void handleMessage( Stanza *stanza, MessageSession *session )
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 if(stanza->findChildWithAttrib("xmlns","jabber:x:delay"))
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 printf("History message, ignoring.\n");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 return;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 printf("Message.\n");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 /* push functions and arguments */
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66 lua_getglobal(L, "onMessage"); /* function to be called */
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 if(!lua_isfunction(L, -1))
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 printf("Unhandled message... please add an onMessage function to the script\n");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70 return;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
71 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
72 lua_newtable(L);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 lua_pushstring(L, stanza->body().c_str());
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74 lua_setfield(L,-2, "body");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 lua_pushstring(L, stanza->from().full().c_str());
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76 lua_setfield(L,-2, "fromFull");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
77 lua_pushstring(L, stanza->from().bare().c_str());
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
78 lua_setfield(L,-2, "fromBare");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
79 lua_pushstring(L, stanza->to().full().c_str());
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
80 lua_setfield(L,-2, "to");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
81 lua_pushnumber(L, stanza->subtype());
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
82 lua_setfield(L,-2, "type");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
83
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
84 /* do the call (1 argument, 1 result) */
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
85 if (lua_pcall(L, 1, 1, 0) != 0)
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
86 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
87 printf("Error running function `onMessage': %s",lua_tostring(L, -1));
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
88 return;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
89 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
90 if(lua_istable(L, -1))
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
91 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
92 Tag *t = new Tag( "message" );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94 lua_getfield(L, -1, "type");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 t->addAttribute( "type", luaL_optlstring(L, -1, "chat", NULL) );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 lua_pop(L,1);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
97 lua_getfield(L, -1, "to");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98 t->addAttribute( "to", luaL_optlstring(L, -1, stanza->from().bare().c_str(), NULL )); //
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99 lua_pop(L,1);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100 lua_getfield(L, -1, "from");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
101 t->addAttribute( "from", luaL_optlstring(L, -1, j->jid().full().c_str(), NULL ));
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
102 lua_pop(L,1);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
103 lua_getfield(L, -1, "body");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
104 t->addChild( new Tag( "body", luaL_optlstring(L, -1, "", NULL) ) );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
105 lua_pop(L,1);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
106 j->send( t ); // Send it!
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
107 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
108
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
110 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
112 virtual void onConnect()
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
114 // do something when the connection is established
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115 printf("Connecting...");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 if(L)
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
117 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 lua_pushinteger(L, StanzaMessageChat);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 lua_setglobal(L, "MSG_CHAT");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120 lua_pushinteger(L, StanzaMessageGroupchat);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121 lua_setglobal(L, "MSG_GROUPCHAT");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122 lua_pushinteger(L, StanzaMessageNormal);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
123 lua_setglobal(L, "MSG_NORMAL");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
124 lua_pushinteger(L, StanzaMessageError);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
125 lua_setglobal(L, "MSG_ERROR");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
127 lua_pushinteger(L, StanzaPresenceError);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
128 lua_setglobal(L, "PRE_ERROR");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
129 lua_pushinteger(L, StanzaPresenceAvailable);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
130 lua_setglobal(L, "PRE_AVAILABLE");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
131 lua_pushinteger(L, StanzaPresenceUnavailable);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
132 lua_setglobal(L, "PRE_UNAVAILABLE");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
133
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
134 lua_register(L, "JoinMUC", lcJoinMUC);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135 lua_register(L, "Sleep", lcSleep);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
136 lua_register(L, "MemUsage", lcMemUsage);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137 lua_register(L, "SendPresence", lcSendPresence);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
138 lua_register(L, "SendMessage", lcSendMessage);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
139 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
140 else
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
141 printf("Lua not loaded?!\n");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
142
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
143 printf("Connected.\n");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
144
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
145 lua_getglobal(L, "onConnect"); /* function to be called */
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
146 if(!lua_isfunction(L, -1))
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
147 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
148 printf("No onConnect() function found.\n");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
149 return;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
150 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
151
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
152 /*Tag *t = new Tag( "presence" );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
153 t->addAttribute( "to", "test@conference.jabber.org/Betty" );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
154 t->addChild(new Tag( "status", "Betty!" ) );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
155 j->send( t ); */
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
156
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
157 /* do the call (0 arguments, 0 results) */
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
158 if (lua_pcall(L, 0, 0, 0) != 0)
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
159 return; // error(L, "error running function `f': %s",lua_tostring(L, -1));
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
160
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
161 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
162
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
163 virtual void handlePresence( Stanza * stanza)
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
164 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
165 printf("Presence.\n");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
166 /* push functions and arguments */
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
167 lua_getglobal(L, "onPresence"); /* function to be called */
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
168 if(!lua_isfunction(L, -1))
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
169 return;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
170
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
171 lua_newtable(L);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
172 lua_pushstring(L, stanza->body().c_str());
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
173 lua_setfield(L,-2, "body");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
174 lua_pushstring(L, stanza->from().full().c_str());
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
175 lua_setfield(L,-2, "fromFull");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
176 lua_pushstring(L, stanza->from().bare().c_str());
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
177 lua_setfield(L,-2, "fromBare");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
178 lua_pushstring(L, stanza->to().full().c_str());
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
179 lua_setfield(L,-2, "to");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
180 lua_pushnumber(L, stanza->subtype());
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
181 lua_setfield(L,-2, "ntype");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
182 lua_pushstring(L, stanza->findAttribute("type").c_str());
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
183 lua_setfield(L,-2, "type");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
184
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
185
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
186
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
187 /* do the call (1 arguments, 0 results) */
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
188 if (lua_pcall(L, 1, 0, 0) != 0)
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
189 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
190 printf("Error running function `onPresence': %s",lua_tostring(L, -1));
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
191 return;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
192 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
193 return;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
194 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
195
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
196 virtual bool onTLSConnect( const CertInfo& info )
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
197 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
198 // decide whether you trust the certificate, examine the CertInfo structure
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
199 // It's not like a bot is bothered with this :)
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
200 return true; // if you trust it, otherwise return false
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
201 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
202
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
203 virtual void onDisconnect(gloox::ConnectionError e)
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
204 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
205 std::string msg;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
206 if (e == ConnStreamError)
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
207 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
208
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
209 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
210 switch(e)
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
211 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
212 case ConnStreamError:
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
213 msg = j->streamErrorText();
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
214 break;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
215 case ConnIoError:
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
216 msg = "An I/O error occured";
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
217 break;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
218 default:
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
219 msg = "Unknown error";
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
220 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
221 printf("Disconnected: %s\n", msg.c_str());
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
222 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
223
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
224 virtual void handleLog( LogLevel level, LogArea area, const std::string & message)
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
225 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
226 printf("Log: %s\n", message.c_str());
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
227 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
228
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
229 public:
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
230 Component* j;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
231 };
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
232
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
233
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
234 int main( int argc, char* argv[] )
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
235 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
236 L = lua_open(); /* opens Lua */
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
237 if(L == NULL)
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
238 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
239 printf("Unable to initialize Lua.\n");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
240 exit(1);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
241 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
242 else
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
243 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
244
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
245 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
246 luaL_openlibs(L);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
247 if(luaL_dofile(L, "bot.lua"))
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
248 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
249 printf("Unable to load/run the bot file\n\t%s\n", lua_tostring(L, -1));
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
250 exit(1);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
251 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
252 else
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
253 printf("File loaded successfully.\n");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
254
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
255 Bot b;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
256 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
257
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
258 int lcJoinMUC(lua_State* L)
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
259 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
260 printf("Joining MUC...\n");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
261 if(!lua_isstring(L,1))
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
262 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
263 printf("Ooops, not passed a string :(\n");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
264 return 0;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
265 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
266 Tag *t = new Tag( "presence" );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
267 t->addAttribute( "to", lua_tostring(L, 1) );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
268 if (lua_isstring(L, 2))
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
269 t->addAttribute( "type", lua_tostring(L, 2) );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
270
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
271 // t->addChild("status", "Betty!");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
272 t->addChild(new Tag( "status", "" ) );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
273 printf(t->xml().c_str() );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
274 theBot->j->send( t );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
275 //
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
276 printf("Conference (%s) joined.\n",lua_tostring(L, 1));
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
277 return 0;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
278 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
279
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
280 int lcLeaveMUC(lua_State* L)
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
281 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
282 if(!lua_isstring(L,1))
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
283 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
284 printf("Ooops, not passed a string :(\n");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
285 return 0;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
286 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
287 Tag *t = new Tag( "presence" );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
288 t->addAttribute( "to", lua_tostring(L, 1) );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
289 t->addAttribute( "type", "unavailable" );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
290 t->addChild(new Tag( "status", "" ) );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
291 theBot->j->send( t );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
292 printf("Conference (%s) joined.\n",lua_tostring(L, 1));
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
293 return 0;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
294 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
295
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
296 int lcSleep(lua_State* L)
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
297 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
298 sleep((int)lua_tonumber(L, 1));
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
299 return 0;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
300 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
301
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
302 int lcMemUsage(lua_State* L)
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
303 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
304 lua_pushinteger(L, lua_gc(L, LUA_GCCOUNT, 0));
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
305 return 1;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
306 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
307
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
308 // function SendPresence(to, type, text[, from]);
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
309 int lcSendPresence(lua_State* L)
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
310 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
311 if(!lua_isstring(L,1))
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
312 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
313 printf("Ooops, not passed a string :(\n");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
314 // lua_error(L,
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
315 return 0;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
316 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
317 Tag *t = new Tag( "presence" );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
318 t->addAttribute( "to", lua_tostring(L, 1) );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
319 if (lua_isstring(L, 2))
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
320 t->addAttribute( "type", lua_tostring(L, 2) );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
321 else
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
322 t->addAttribute( "type", "available" );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
323
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
324 if (lua_isstring(L, 3))
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
325 t->addChild(new Tag( "status", lua_tostring(L, 3) ) );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
326 else
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
327 t->addChild(new Tag( "status", "" ) );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
328
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
329 if (lua_isstring(L, 4))
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
330 t->addAttribute( "from", lua_tostring(L, 4) );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
331
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
332 t->addChild(new Tag("x", "xmlns", "http://jabber.org/protocol/muc#user"));
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
333
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
334 theBot->j->send( t );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
335 return 0;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
336 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
337
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
338 int lcSendMessage(lua_State* L)
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
339 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
340 if(!lua_isstring(L,1))
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
341 {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
342 printf("Ooops, not passed a string :(\n");
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
343 // lua_error(L,
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
344 return 0;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
345 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
346 Tag *t = new Tag( "message" );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
347 t->addAttribute( "to", lua_tostring(L, 1) );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
348
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
349 if (lua_isstring(L, 2))
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
350 t->addAttribute( "from", lua_tostring(L, 2) );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
351
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
352 if (lua_isstring(L, 3))
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
353 t->addChild(new Tag( "body", lua_tostring(L, 3) ) );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
354 else
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
355 t->addChild(new Tag( "body", "" ) );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
356
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
357 if (lua_isstring(L, 4))
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
358 t->addAttribute( "type", lua_tostring(L, 4) );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
359 else
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
360 t->addAttribute( "type", "normal" );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
361
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
362
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
363 theBot->j->send( t );
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
364 return 0;
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
365 }

mercurial