File: handle_game.lua

package info (click to toggle)
pvpgn 1.99.7.2.1%2Bdfsg-3
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 8,300 kB
  • sloc: cpp: 118,407; xml: 6,367; sh: 1,558; ansic: 1,300; perl: 604; cs: 382; python: 308; php: 130; awk: 73; makefile: 19
file content (107 lines) | stat: -rw-r--r-- 2,877 bytes parent folder | download | duplicates (2)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
--[[
	Copyright (C) 2014 HarpyWar (harpywar@gmail.com)
	
	This file is a part of the PvPGN Project http://pvpgn.pro
	Licensed under the same terms as Lua itself.
]]--


-- Global function to handle game create
function handle_game_create(game)
	--for i,j in pairs(game) do
	--	api.message_send_text(game.owner, message_type_info, game.owner, i.." = "..j)
	--end
end




-- Global function to handle user join to game
function handle_game_userjoin(game, account)
	if config.ghost then
		gh_handle_game_userjoin(game, account)
	end
	

end


-- Global function to handle user left from game
function handle_game_userleft(game, account)
	--for username in string.split(str,",")  do
	--	if (account.name ~= username) then
	--		api.message_send_text(username, message_type_whisper, nil, "Bye ".. account.name)
	--	end
    --end
end

-- Global function to handle game end
function handle_game_end(game)
	--api.message_send_text(game.owner, message_type_whisper, nil, "End game")
end

-- Global function to handle game report
function handle_game_report(game)

	--for i,j in pairs(game) do
	--	api.message_send_text("harpywar", message_type_info, game.owner, i.." = "..j)
	--	api.message_send_text(game.owner, message_type_info, game.owner, i.." = "..j)
	--end
	
	--DEBUG(game.last_access)
end



-- Global function to handle game destroy
function handle_game_destroy(game)
	--api.message_send_text(game.owner, message_type_whisper, nil, "Destroy game")
end


-- Global function to handle game status
function handle_game_changestatus(game)
	--api.message_send_text(game.owner, message_type_info, nil, "Change status of the game to ".. game.status)
end


function handle_game_list(account)
	local gamelist = {}
	
	if (config.ghost and config.ghost_dota_server and account.clienttag == CLIENTTAG_WAR3XP) then
		-- get gamelist
		local glist = server_get_games()
		-- and add ping field for each game
		for i,game in pairs(glist) do
			glist[i].ping = 1000 -- initial ping value for all games
			-- if game owner is ghost bot
			if gh_is_bot(game.owner) then
				local pings = account_get_botping(account.name)
				local is_found = false
				for k,v in pairs(pings) do
					-- fetch user ping for current bot
					if (v.bot == game.owner) then
						glist[i].ping = pings[k].ping
						is_found = true
					end
				end
				-- if ping not found for the bot then use ping "0" to move the game on top
				-- (so, after join the game user will receive a ping from the bot)
				if not is_found then
					glist[i].ping = 0
				end
			end
		end
		
		-- sort gamelist by ping ascending
		table.sort(glist, function(a,b) return tonumber(a.ping) < tonumber(b.ping) end)
		
		-- iterate sorted gamelist and fill a final list with a new order
		for i,game in pairs(glist) do
			table.insert(gamelist, game.id)
			table.insert(gamelist, game.name)
		end
		
		return {"id", "name"}, gamelist
	end
end