Skip to content

Commit aecb203

Browse files
committed
Added team message command and new irc client
1 parent d05b7d3 commit aecb203

File tree

8 files changed

+223
-246
lines changed

8 files changed

+223
-246
lines changed

resources/irc/acl.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<command name="!m" level="0" echoChannelOnly="true" />
77
<command name="!players" level="0" echoChannelOnly="true" />
88
<command name="!pm" level="0" echoChannelOnly="true" />
9+
<command name="!ts" level="0" echoChannelOnly="true" />
910
<command name="!getip" level="2" echoChannelOnly="true" />
1011
<command name="!getserial" level="2" echoChannelOnly="true" />
1112
<command name="!mute" level="2" echoChannelOnly="true" />

resources/irc/meta.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
<export function="ircGetServerChannels" type="server" http="false" />
9191
<export function="ircSetUserMode" type="server" http="false" />
9292
<export function="ircGetUserMode" type="server" http="false" />
93+
<export function="ircGetUserChannels" type="server" http="false" />
9394
<export function="ircGetUserNick" type="server" http="false" />
9495
<export function="ircGetUserServer" type="server" http="false" />
9596
<export function="ircGetUsers" type="server" http="false" />

resources/irc/scripts/handling.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ addEventHandler("onIRCRaw",root,
146146
user = createElement("irc-user")
147147
users[user] = {nick,"+iwxz","?","?","?",{channel}}
148148
setElementParent(user,source)
149+
table.insert(channels[channel][4],user)
149150
end
150151
if not userlevels[channel] then
151152
userlevels[channel] = {}

resources/irc/scripts/ircclient_client.lua

Lines changed: 127 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -6,210 +6,178 @@
66
-- Date: 31.10.2010
77
---------------------------------------------------------------------
88

9-
local tabs = {}
10-
local edits = {}
11-
local memos = {}
12-
local messages = {}
13-
local gridlists = {}
14-
local memolines = {}
159
local x,y = guiGetScreenSize()
10+
local g_channels = {}
11+
local window
1612

1713
------------------------------------
1814
-- Irc client
1915
------------------------------------
20-
addCommandHandler("irc",
21-
function ()
22-
if window then
23-
guiGridListSetSortingEnabled(gridlist,true)
24-
guiSetInputEnabled(true)
25-
guiSetVisible(window,true)
26-
guiSetVisible(exitbutton,true)
27-
showCursor(true)
28-
else
29-
triggerServerEvent("startIRCClient",getLocalPlayer())
30-
end
31-
end,false,false
32-
)
33-
34-
addEvent("showIrcClient",true)
35-
addEventHandler("showIrcClient",root,
36-
function (info)
37-
window = guiCreateWindow(0.25,0.3,0.5,0.6,"Internet Relay Chat",true)
38-
exitbutton = guiCreateButton(0.95,0.03,0.2,0.03,"Close",true,window)
39-
tabpanel = guiCreateTabPanel(0,0.08,1,0.9,true,window)
40-
guiSetProperty(exitbutton,"AlwaysOnTop","True")
41-
--guiWindowSetMovable(window,false)
42-
--guiWindowSetSizable(window,false)
43-
for i,inf in ipairs (info) do
44-
local chantitle = inf[1]
45-
local tab = guiCreateTab(chantitle,tabpanel)
46-
local edit = guiCreateEdit(0.005,0.915,0.74,0.07,"",true,tab)
47-
local memo = guiCreateMemo(0.005,0.01,0.74,0.9,"",true,tab)
48-
local gridlist = guiCreateGridList(0.75,0.01,0.245,0.99,true,tab)
49-
local column = guiGridListAddColumn(gridlist,"Users",0.8)
50-
guiGridListSetSortingEnabled(gridlist,true)
51-
for i,user in ipairs (inf[2]) do
16+
addEvent("ircStartClient",true)
17+
addEventHandler("ircStartClient",root,
18+
function (channels)
19+
window = guiCreateWindow((x/2)-320,(y/2)-240,640,480,"Internet Relay Chat",false)
20+
local tabpanel = guiCreateTabPanel(0.01,0.05,0.98,0.95,true,window)
21+
for i,channel in ipairs (channels) do
22+
local tab = guiCreateTab(channel.name,tabpanel)
23+
local memo = guiCreateMemo(0.01,0.01,0.75,0.90,"* Topic is: "..channel.topic.."\n",true,tab)
24+
local edit = guiCreateEdit(0.01,0.92,0.75,0.07,"",true,tab)
25+
local gridlist = guiCreateGridList(0.76,0.01,0.23,0.90,true,tab)
26+
local hidebtn = guiCreateButton(0.76,0.92,0.11,0.07,"Hide",true,tab)
27+
local closebtn = guiCreateButton(0.88,0.92,0.11,0.07,"Close",true,tab)
28+
guiGridListAddColumn(gridlist,"users",0.88)
29+
guiMemoSetReadOnly(memo,true)
30+
for i,user in ipairs (channel.users) do
5231
local row = guiGridListAddRow(gridlist)
53-
guiGridListSetItemText(gridlist,row,column,getIconFromLevel(user[2])..user[1],false,false)
32+
guiGridListSetItemText(gridlist,row,1,getIconFromLevel(user.level)..user.name,false,false)
33+
guiGridListSetItemData(gridlist,row,1,user.name)
5434
end
55-
tabs[chantitle] = tab
56-
edits[chantitle] = edit
57-
memos[chantitle] = memo
58-
gridlists[chantitle] = gridlist
59-
memolines[memo] = {}
35+
guiGridListSetSortingEnabled(gridlist,true)
36+
addEventHandler("onClientGUIClick",closebtn,ircStopClient,false)
37+
addEventHandler("onClientGUIClick",hidebtn,ircHideClient,false)
38+
addEventHandler("onClientGUIAccepted",edit,
39+
function (edit)
40+
local text = guiGetText(edit)
41+
if text and text ~= "" then
42+
triggerServerEvent("ircSendMessage",resourceRoot,localPlayer,channel.name,text)
43+
guiSetText(edit,"")
44+
end
45+
end
46+
)
47+
g_channels[channel.name] = {memo=memo,edit=edit,gridlist=gridlist}
6048
end
61-
guiBringToFront(exitbutton)
6249
guiSetInputEnabled(true)
63-
showCursor(true)
6450
end
6551
)
6652

67-
addEventHandler("onClientGUIAccepted",root,
68-
function (editbox)
69-
for chantitle,edit in pairs (edits) do
70-
if edit == editbox then
71-
triggerServerEvent("ircSay",getLocalPlayer(),chantitle,guiGetText(editbox))
72-
guiSetText(editbox,"")
73-
return
74-
end
75-
end
76-
end
77-
)
78-
79-
addEventHandler("onClientGUIClick",root,
80-
function (btn)
81-
if btn ~= "left" then return end
82-
if source == exitbutton then
83-
guiSetInputEnabled(false)
84-
guiSetVisible(window,false)
85-
guiSetVisible(exitbutton,false)
53+
addEventHandler("onClientResourceStop",resourceRoot,
54+
function ()
55+
if window then
8656
showCursor(false)
57+
guiSetInputEnabled(false)
8758
end
8859
end
8960
)
9061

91-
addEvent("onClientIRCMessage",true)
92-
addEventHandler("onClientIRCMessage",root,
93-
function (user,chantitle,message)
94-
memoAddLine(memos[chantitle],user..": "..message)
95-
end
96-
)
62+
function ircStopClient ()
63+
destroyElement(window)
64+
window = nil
65+
channels = {}
66+
showCursor(false)
67+
guiSetInputEnabled(false)
68+
triggerServerEvent("ircStopClient",resourceRoot,localPlayer)
69+
end
9770

98-
addEvent("onClientIRCUserJoin",true)
99-
addEventHandler("onClientIRCUserJoin",root,
100-
function (user,chantitle,vhost)
101-
local row = guiGridListAddRow(gridlists[chantitle])
102-
guiGridListSetItemText(gridlists[chantitle],row,1,user,false,false)
103-
memoAddLine(memos[chantitle],"* "..user.." ("..vhost..") joined")
104-
end
105-
)
71+
function ircHideClient ()
72+
guiSetVisible(window,false)
73+
showCursor(false)
74+
guiSetInputEnabled(false)
75+
end
10676

107-
addEvent("onClientIRCUserPart",true)
108-
addEventHandler("onClientIRCUserPart",root,
109-
function (user,chantitle,reason)
110-
for i=1,guiGridListGetRowCount(gridlists[chantitle]) do
111-
if guiGridListGetItemText(gridlists[chantitle],i,1) == user then
112-
guiGridListRemoveRow(gridlists[chantitle],i)
113-
break
114-
end
115-
if string.sub(guiGridListGetItemText(gridlists[chantitle],i,1),2) == user then
116-
guiGridListRemoveRow(gridlists[chantitle],i)
117-
break
118-
end
77+
addCommandHandler("irc",
78+
function ()
79+
if window then
80+
guiSetVisible(window,true)
81+
showCursor(true)
82+
guiSetInputEnabled(true)
11983
end
120-
memoAddLine(memos[chantitle],"* "..user.." parted ("..(reason or "")..")")
121-
end
84+
end,false
12285
)
12386

124-
addEvent("onClientIRCUserQuit",true)
125-
addEventHandler("onClientIRCUserQuit",root,
126-
function (user,reason)
127-
for i,gridlist in pairs (gridlists) do
128-
for i=1,guiGridListGetRowCount(gridlist) do
129-
if guiGridListGetItemText(gridlist,i,1) == user then
130-
guiGridListRemoveRow(gridlist,i)
131-
break
132-
end
133-
end
134-
end
135-
for i,memo in pairs (memos) do
136-
memoAddLine(memo,"* "..user.." ("..vhost..") quit ("..reason..")")
87+
local icons = {"+","%","@","&","~"}
88+
function getIconFromLevel (level)
89+
return icons[level] or ""
90+
end
91+
92+
function getLevelFromIcon (ico)
93+
for i,icon in ipairs (icons) do
94+
if icon == ico then
95+
return i
13796
end
13897
end
139-
)
98+
return false
99+
end
100+
101+
function addMessage (channel,message)
102+
guiSetText(g_channels[channel].memo,guiGetText(g_channels[channel].memo)..""..message)
103+
end
140104

141-
addEvent("onClientIRCNotice",true)
142-
addEventHandler("onClientIRCNotice",root,
143-
function (user,chantitle,message)
144-
memoAddLine(memos[chantitle],"<notice> "..user..": "..message)
105+
addEvent("onIRCMessage",true)
106+
addEventHandler("onIRCMessage",root,
107+
function (user,channel,message)
108+
if g_channels[channel] then
109+
addMessage(channel,"<"..user.."> "..message)
110+
end
145111
end
146112
)
147113

148-
addEvent("onClientIRCUserMode",true)
149-
addEventHandler("onClientIRCUserMode",root,
150-
function (user,chantitle,positive,mode,setter,newlevel)
151-
if positive then
152-
memoAddLine(memos[chantitle],"* "..(setter or "Server").." sets mode: +"..mode.." "..user)
153-
else
154-
memoAddLine(memos[chantitle],"* "..(setter or "Server").." sets mode: -"..mode.." "..user)
114+
addEvent("onIRCUserJoin",true)
115+
addEventHandler("onIRCUserJoin",root,
116+
function (user,channel,vhost)
117+
if g_channels[channel] then
118+
addMessage(channel,"* "..user.." joined ("..vhost..")")
119+
local row = guiGridListAddRow(g_channels[channel].gridlist)
120+
guiGridListSetItemText(g_channels[channel].gridlist,row,1,user,false,false)
121+
guiGridListSetItemData(g_channels[channel].gridlist,row,1,user)
155122
end
156123
end
157124
)
158125

159-
addEvent("onClientIRCChannelMode",true)
160-
addEventHandler("onClientIRCChannelMode",root,
161-
function (chantitle,positive,mode,setter)
162-
if positive then
163-
memoAddLine(memos[chantitle],"* "..(setter or "Server").." sets mode: +"..mode)
164-
else
165-
memoAddLine(memos[chantitle],"* "..(setter or "Server").." sets mode: -"..mode)
126+
addEvent("onIRCUserPart",true)
127+
addEventHandler("onIRCUserPart",root,
128+
function (user,channel,reason)
129+
if g_channels[channel] then
130+
addMessage(channel,"* "..user.." parted ("..reason..")")
131+
for i=0,guiGridListGetRowCount(g_channels[channel].gridlist)-1 do
132+
if guiGridListGetItemData(g_channels[channel].gridlist,i,1) == user then
133+
guiGridListRemoveRow(g_channels[channel].gridlist,i)
134+
end
135+
end
166136
end
167137
end
168138
)
169139

170-
addEvent("onClientIRCLevelChange",true)
171-
addEventHandler("onClientIRCLevelChange",root,
172-
function (user,chantitle,oldlevel,newlevel)
173-
for i=1,guiGridListGetRowCount(gridlists[chantitle]) do
174-
if guiGridListGetItemText(gridlists[chantitle],i,1) == user then
175-
guiGridListSetItemText(gridlists[chantitle],i,1,getIconFromLevel(newlevel)..user,false,false)
176-
break
177-
end
178-
if string.sub(guiGridListGetItemText(gridlists[chantitle],i,1),2) == user then
179-
guiGridListSetItemText(gridlists[chantitle],i,1,getIconFromLevel(newlevel)..user,false,false)
180-
break
140+
addEvent("onIRCUserQuit",true)
141+
addEventHandler("onIRCUserQuit",root,
142+
function (user,reason)
143+
for channel,info in pairs (g_channels) do
144+
for i=0,guiGridListGetRowCount(info.gridlist)-1 do
145+
if guiGridListGetItemData(info.gridlist,i,1) == user then
146+
guiGridListRemoveRow(info.gridlist,i)
147+
addMessage(channel,"* "..user.." quit ("..reason..")")
148+
end
181149
end
182150
end
183151
end
184152
)
185153

186-
addEvent("onClientIRCUserChangeNick",true)
187-
addEventHandler("onClientIRCUserChangeNick",root,
188-
function (oldnick,newnick)
189-
for i,gridlist in pairs (gridlists) do
190-
for i=1,guiGridListGetRowCount(gridlist) do
191-
if guiGridListGetItemText(gridlist,i,1) == oldnick then
192-
guiGridListSetItemText(gridlist,i,1,newnick,false,false)
193-
break
194-
end
195-
if string.sub(guiGridListGetItemText(gridlist,i,1),2) == oldnick then
196-
guiGridListSetItemText(gridlist,i,1,string.sub(guiGridListGetItemText(gridlist,i,1),1,1)..newnick,false,false)
197-
break
154+
addEvent("onIRCLevelChange",true)
155+
addEventHandler("onIRCLevelChange",root,
156+
function (user,channel,oldlevel,newlevel)
157+
if g_channels[channel] then
158+
addMessage(channel,"* "..user.." changed level from "..tostring(oldlevel).." to "..tostring(newlevel))
159+
for i=0,guiGridListGetRowCount(g_channels[channel].gridlist)-1 do
160+
if guiGridListGetItemData(g_channels[channel].gridlist,i,1) == user then
161+
guiGridListSetItemText(g_channels[channel].gridlist,i,1,getIconFromLevel(newlevel)..user,false,false)
198162
end
199163
end
200164
end
201165
end
202166
)
203167

204-
function memoAddLine (memo,line)
205-
if #memolines[memo] > 16 then
206-
table.remove(memolines[memo],1)
168+
addEvent("onIRCUserChangeNick",true)
169+
addEventHandler("onIRCUserChangeNick",root,
170+
function (user,oldnick,newnick)
171+
for channel,info in pairs (g_channels) do
172+
for i=0,guiGridListGetRowCount(info.gridlist)-1 do
173+
if guiGridListGetItemData(info.gridlist,i,1) == oldnick then
174+
addMessage(channel,"* "..oldnick.." is now know as "..newnick)
175+
local oldIcon = string.sub(guiGridListGetItemText(info.gridlist,i,1),1,1)
176+
if not getLevelFromIcon(oldIcon) then oldIcon = "" end
177+
guiGridListSetItemText(info.gridlist,i,1,oldIcon..newnick,false,false)
178+
guiGridListSetItemData(info.gridlist,i,1,newnick)
179+
end
180+
end
181+
end
207182
end
208-
table.insert(memolines[memo],line)
209-
return guiSetText(memo,table.concat(memolines[memo],"\n"))
210-
end
211-
212-
local icons = {"+","%","@","&","~"}
213-
function getIconFromLevel (level)
214-
return icons[level] or ""
215-
end
183+
)

0 commit comments

Comments
 (0)