| 1 | --[[ |
| 2 | Copyright (C) 2014 HarpyWar ([email protected]) |
| 3 | |
| 4 | This file is a part of the PvPGN Project http://pvpgn.pro |
| 5 | Licensed under the same terms as Lua itself. |
| 6 | ]]-- |
| 7 | |
| 8 | |
| 9 | -- Global function to handle game create |
| 10 | function handle_game_create(game) |
| 11 | --for i,j in pairs(game) do |
| 12 | -- api.message_send_text(game.owner, message_type_info, game.owner, i.." = "..j) |
| 13 | --end |
| 14 | end |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | -- Global function to handle user join to game |
| 20 | function handle_game_userjoin(game, account) |
| 21 | if config.ghost then |
| 22 | gh_handle_game_userjoin(game, account) |
| 23 | end |
| 24 | |
| 25 | |
| 26 | end |
| 27 | |
| 28 | |
| 29 | -- Global function to handle user left from game |
| 30 | function handle_game_userleft(game, account) |
| 31 | --for username in string.split(str,",") do |
| 32 | -- if (account.name ~= username) then |
| 33 | -- api.message_send_text(username, message_type_whisper, nil, "Bye ".. account.name) |
| 34 | -- end |
| 35 | --end |
| 36 | end |
| 37 | |
| 38 | -- Global function to handle game end |
| 39 | function handle_game_end(game) |
| 40 | --api.message_send_text(game.owner, message_type_whisper, nil, "End game") |
| 41 | end |
| 42 | |
| 43 | -- Global function to handle game report |
| 44 | function handle_game_report(game) |
| 45 | |
| 46 | --for i,j in pairs(game) do |
| 47 | -- api.message_send_text("harpywar", message_type_info, game.owner, i.." = "..j) |
| 48 | -- api.message_send_text(game.owner, message_type_info, game.owner, i.." = "..j) |
| 49 | --end |
| 50 | |
| 51 | --DEBUG(game.last_access) |
| 52 | end |
| 53 | |
| 54 | |
| 55 | |
| 56 | -- Global function to handle game destroy |
| 57 | function handle_game_destroy(game) |
| 58 | --api.message_send_text(game.owner, message_type_whisper, nil, "Destroy game") |
| 59 | end |
| 60 | |
| 61 | |
| 62 | -- Global function to handle game status |
| 63 | function handle_game_changestatus(game) |
| 64 | --api.message_send_text(game.owner, message_type_info, nil, "Change status of the game to ".. game.status) |
| 65 | end |
| 66 | |
| 67 | |
| 68 | function handle_game_list(account) |
| 69 | local gamelist = {} |
| 70 | |
| 71 | if (config.ghost and config.ghost_dota_server and account.clienttag == CLIENTTAG_WAR3XP) then |
| 72 | -- get gamelist |
| 73 | local glist = server_get_games() |
| 74 | -- and add ping field for each game |
| 75 | for i,game in pairs(glist) do |
| 76 | glist[i].ping = 1000 -- initial ping value for all games |
| 77 | -- if game owner is ghost bot |
| 78 | if gh_is_bot(game.owner) then |
| 79 | local pings = account_get_botping(account.name) |
| 80 | local is_found = false |
| 81 | for k,v in pairs(pings) do |
| 82 | -- fetch user ping for current bot |
| 83 | if (v.bot == game.owner) then |
| 84 | glist[i].ping = pings[k].ping |
| 85 | is_found = true |
| 86 | end |
| 87 | end |
| 88 | -- if ping not found for the bot then use ping "0" to move the game on top |
| 89 | -- (so, after join the game user will receive a ping from the bot) |
| 90 | if not is_found then |
| 91 | glist[i].ping = 0 |
| 92 | end |
| 93 | end |
| 94 | end |
| 95 | |
| 96 | -- sort gamelist by ping ascending |
| 97 | table.sort(glist, function(a,b) return tonumber(a.ping) < tonumber(b.ping) end) |
| 98 | |
| 99 | -- iterate sorted gamelist and fill a final list with a new order |
| 100 | for i,game in pairs(glist) do |
| 101 | table.insert(gamelist, game.id) |
| 102 | table.insert(gamelist, game.name) |
| 103 | end |
| 104 | |
| 105 | return {"id", "name"}, gamelist |
| 106 | end |
| 107 | end |