File: ingame_lobby.example.lua

package info (click to toggle)
spring 88.0%2Bdfsg1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 41,524 kB
  • sloc: cpp: 343,114; ansic: 38,414; python: 12,257; java: 12,203; awk: 5,748; sh: 1,204; xml: 997; perl: 405; objc: 192; makefile: 181; php: 134; sed: 2
file content (91 lines) | stat: -rwxr-xr-x 2,007 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
do
	return false -- don't show this widget in the userlist by default
end

function widget:GetInfo()
	return {
		name      = "Ingame lobby",
		desc      = "stuff",
		author    = "Auswaschbar (updated by jK)",
		date      = "",
		license   = "GNU GPL v3",
		layer     = 0,
		enabled   = true
	}
end

local username = "foo"
local password = "bar"

local Echo = Spring.Echo
local LuaLobby = Script.CreateLobby()
local curChannel

function LuaLobby.DoneConnecting(success, errMsg)
	if (success) then
		Echo("Connection completed");
		LuaLobby:Login(username, password)
	else
		Echo("Connection error: " .. errMsg);
	end
end

function LuaLobby.LoginEnd()
	Echo("Logged in to server");
end

function LuaLobby.LoginDenied(errMsg)
	Echo("Cannot login: " .. errMsg);
end

function LuaLobby.Joined(channel)
	if (curChannel) then
		LuaLobby:LeaveChannel(curChannel);
	end
	curChannel = channel
	Echo("Joined channel: " .. channel);
end

function LuaLobby.ChannelTopic(channel, author, time, topic)
	Echo(channel .. " topic: " .. topic);
	Echo("Set by " .. author .. " in " .. time)
end

function LuaLobby.Said(channel, user, message)
	Echo("["..channel.."]<"..user..">: " .. message);
end

function LuaLobby.SaidEx(channel, user, message)
	Echo("["..channel.."] "..user.." " .. message);
end

function LuaLobby.NetworkError(errMsg)
	Echo("Network error: " .. errMsg);
end

function LuaLobby.ChannelInfo(channel, num_users)
	Echo("["..channel.."] "..num_users);
end

function widget:Initialize()
	LuaLobby:Connect("lobby.springrts.com", 8200);
end

function widget:Update()
	LuaLobby:Poll()
end

function widget:TextCommand(command)
	if (string.find(command, 'lsayex') == 1) then
		LuaLobby:SayEx(curChannel, command:sub(8))
	elseif (string.find(command, 'lsay') == 1) then
		LuaLobby:Say(curChannel, command:sub(6))
	elseif (string.find(command, 'ljoin') == 1) then
		LuaLobby:JoinChannel(command:sub(7))
	elseif (string.find(command, 'lchan') == 1) then
		LuaLobby:Channels()
	end
end

function widget:Shutdown()
end