Sat, 27 Mar 2010 17:43:08 +0000
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 | --[[ Lua XMPP MOO Component by Matthew Wild (MattJ) ]] |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 | function onMessage(msg) |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 | success, message = pcall(handleMessage, msg); |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 | if not success then print("\nERROR: "..message.."\n"); end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 | function handleMessage(msg) |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 | local action, object, room, server, person; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 | person = people[msg.fromFull] |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 | room = people["local"].room._properties.name; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 | if not person then print("No such person as "..msg.fromFull, tostring(people[msg.fromFull]).."\n"); end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 | if not rooms[room] then return; end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 | person:_processCommand(msg.body); |
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 | return nil; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 | end |
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 | function GetOccupantNick(jid) |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 | local pjid, p |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 | for pjid, p in pairs(people) do |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 | if CompareJIDs(pjid, jid) then return p.nick; end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 | return "user"; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 | function CompareJIDs(j1, j2) |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 | return j1 == j2; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 | function MoveToRoom(person, room) |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 | if not ( person and room) then print("Error, can't move person to room, invalid args"); return; end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 | if type(room) ~= "table" then |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 | if not rooms[room] then rooms[room] = CreateObject(classes.obj_room, room); rooms[room]:_create{ room = room, server = "" }; end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 | room = rooms[room]; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 | if person.room ~= room then |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 | if person.room then |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 | person.room.people[person.nick] = nil; -- Remove from room |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 | person.room = room; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 | --table.print("rooms", rooms); |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 | room.people[person.nick] = person; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 | room:_enter{ room = person.room, person = person, nick = person.nick }; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 | function RemoveFromRoom(room, jid) |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 | if not ( room and jid) then return; end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 | for id, t in pairs(room.people) do |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 | room.people[id] = nil; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 | function BroadcastMessage(people_, from, text, mtype, sender_sees) |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 | print("\n|>>"..from..": "..text); |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 | function FSay(room, fromnick, text) |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 | if text and fromnick then print("\n|>>"..fromnick..": "..text); end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 | function SendMessage(to, from, text, type) |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 | if to == "local" then print("\n>>"..from..": "..text); |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 | else print("\n|>>"..(from or "")..": "..text); end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 | function PSay(room, tonick, fromnick, text) |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 | print("\n>>"..fromnick..": "..text); |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 | dofile("common.lua"); |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 | rooms = rooms or { }; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 | people = people or { ["local"] = setmetatable({ nick = "user", group = {} }, { __index = occupant }); }; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 | people["local"]._contents = { ["in"] = createcontainertable(); }; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 | -- Single user -- |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 | if not people["local"].room then MoveToRoom(people["local"],"lounge"); end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 | io.write("\n> "); |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 | for line in io.lines() do |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 | onMessage({ fromFull = "local", body = line }); |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 | io.write("\n> "); |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 | end |