Skip to content

Commit

Permalink
Lua scripts pack. It is a part of PvPGN now.
Browse files Browse the repository at this point in the history
First large implementation in Lua is Trivia Quiz Game (/quiz command) http://i.imgur.com/8QV3blt.png
  • Loading branch information
HarpyWar committed May 26, 2014
1 parent 4d86259 commit ee04fdd
Show file tree
Hide file tree
Showing 36 changed files with 7,534 additions and 22 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@ option(WITH_PGSQL "include PostgreSQL user accounts support" OFF)
option(WITH_ODBC "include ODBC user accounts support" OFF)
include(ConfigureChecks.cmake)

subdirs(src conf man files lua)
subdirs(src conf man files)
if(WITH_LUA)
add_subdirectory(lua)
endif(WITH_LUA)

ENABLE_TESTING()
50 changes: 32 additions & 18 deletions conf/bnhelp.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
--------------------------------------------------------
/games all
Displays a list of all games.
/games [l]obby
/games l[obby]
Displays a list of games in lobby.

%channels chs
Expand Down Expand Up @@ -383,11 +383,11 @@
--------------------------------------------------------
/mail <command> [options]
--------------------------------------------------------
/mail [s]end <receiver> <message>
/mail s[end] <receiver> <message>
Sends mail to <receiver> with <message>.
/mail [r]ead [index]
/mail r[ead] [index]
Reads mail [index]
/mail [del]ete {all|<index>}
/mail del[ete] {all|<index>}
Deletes mail <index> or [all] mail.

%flag
Expand All @@ -411,7 +411,7 @@
--------------------------------------------------------
/ipban <command> [option] [time]
--------------------------------------------------------
/ipban [l[ist]]
/ipban l[ist]
Displays a list of banned IP addresses
/ipban c[heck] <IP>
Checks if IP address <IP> is banned or not.
Expand Down Expand Up @@ -460,25 +460,25 @@
Create a new clan (max <clantag> length = 4; spaces are allowed in <clanname>)

Commands for clan members:
/clan [m]sg <message> (alias [w]hisper)
/clan m[sg] <message> (alias [w]hisper)
Whispers a message to all your fellow clan members
/clan [inv]ite <username>
/clan inv[ite] <username>
Invite <username> to your clan.
/clan [inv]ite get
/clan inv[ite] get
Show clanname which you have been invited
/clan [inv]ite accept
/clan inv[ite] accept
Accept invitation to clan
/clan [inv]ite decline
/clan inv[ite] decline
Decline invitation to clan

Commands for clan chieftain:
/clan motd <message>
Update the clan's Message of the Day to <message>.
/clan [pub]lic (alias: pub)
/clan pub[lic] (alias: pub)
Opens the clan channel up to the public so that anyone may enter.
/clan [priv]ate (alias: priv)
/clan priv[ate] (alias: priv)
Closes the clan channel such that only members of the clan may enter.
/clan [dis]band
/clan dis[band]
Disband your clan.

%ping p latency
Expand Down Expand Up @@ -589,13 +589,27 @@ Commands for clan chieftain:
Use /icon without [name] to display list of available icons in your stash.
--------------------------------------------------------
Syntax for operator/admin:
/icon [a]dd <username> <icon>
/icon a[dd] <username> <icon>
Add icon into user stash
/icon [d]el <username> <icon>
/icon d[el] <username> <icon>
Remove icon from user stash
/icon [s]et <username> <icon>
/icon s[et] <username> <icon>
Set custom icon to user without adding it in user stash
/icon [l]ist <username>
/icon l[ist] <username>
Display icons in user's stash
/icon [l]ist
/icon l[ist]
Display availaible icons in server stash that can be assigned to users

%quiz
--------------------------------------------------------
/quiz <command> [option]
Trivia Quiz Game
--------------------------------------------------------
/quiz start <name>
Start game with given dictionary name in current channel
/quiz stop
Finish game by force
/quiz stats [username]
Display record statistics for user
/quiz stats
Display Top records
19 changes: 16 additions & 3 deletions lua/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
# TODO: add lua files here
# copy all files from lua directory

file(GLOB DEPLOY_FILES_AND_DIRS "${PROJECT_SOURCE_DIR}/lua/*")

foreach(ITEM ${DEPLOY_FILES_AND_DIRS})
IF( IS_DIRECTORY "${ITEM}" )
LIST( APPEND DIRS_TO_DEPLOY "${ITEM}" )
ELSE()
IF(NOT ${ITEM} MATCHES "CMakeLists.txt")
LIST( APPEND FILES_TO_DEPLOY "${ITEM}" )
ENDIF(NOT ${ITEM} MATCHES "CMakeLists.txt")
ENDIF()
endforeach()

INSTALL( FILES ${FILES_TO_DEPLOY} DESTINATION ${LOCALSTATEDIR}/lua )
INSTALL( DIRECTORY ${DIRS_TO_DEPLOY} DESTINATION ${LOCALSTATEDIR}/lua )

install(FILES
DESTINATION ${LOCALSTATEDIR}/lua)
32 changes: 32 additions & 0 deletions lua/command/redirect.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--[[
Copyright (C) 2014 HarpyWar ([email protected])
This file is a part of the PvPGN Project http://pvpgn.pro
Licensed under the same terms as Lua itself.
]]--


-- Send text to user from server. Works like /announce,
-- but directly to user and message text is not red.
-- /redirect <username> <message>
function command_redirect(account, text)

local args = split_command(text, 2)

if not args[1] or not args[2] then
api.describe_command(account.name, args[0])
return 1
end

-- get destination account
local dest = api.account_get_by_name(args[1])

if next(dest) == nil or dest.online == "false" then
api.message_send_text(account.name, message_type_error, account.name, "User '" ..args[1].. "' is offline")
return 1
end

api.message_send_text(dest.name, message_type_info, dest.name, args[2])

return 1
end
29 changes: 29 additions & 0 deletions lua/command/w3motd.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--[[
Copyright (C) 2014 HarpyWar ([email protected])
This file is a part of the PvPGN Project http://pvpgn.pro
Licensed under the same terms as Lua itself.
]]--


--
-- Read file w3motd.txt line by line and send text to user
--

local username = nil

function command_w3motd(account, text)
-- allow warcraft 3 client only
if not (account.clienttag == "W3XP" or account.clienttag == "WAR3") then
return 0
end

username = account.name
local data = file_load(config.motdw3file, w3motd_sendline_callback)

return 1
end

function w3motd_sendline_callback(line)
api.message_send_text(username, message_type_info, nil, line)
end
23 changes: 23 additions & 0 deletions lua/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--[[
Copyright (C) 2014 HarpyWar ([email protected])
This file is a part of the PvPGN Project http://pvpgn.pro
Licensed under the same terms as Lua itself.
]]--


-- Config table can be extended here with your own variables
-- values are preloaded from bnetd.conf
config = {
-- Quiz settings
quiz = true,
quiz_filelist = "misc, dota, warcraft", -- display available files in "/quiz start"
quiz_competitive_mode = true, -- top players loses half of points which last player received; at the end top of records loses half of points which players received in current game
quiz_max_questions = 100, -- from start to end
quiz_question_delay = 5, -- delay before send next question
quiz_hint_delay = 20, -- delay between prompts
quiz_users_in_top = 15, -- how many users display in TOP list
quiz_channel = nil, -- (do not modify!) channel when quiz has started (it assigned with start)

}

26 changes: 26 additions & 0 deletions lua/extend/account.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--[[
Copyright (C) 2014 HarpyWar ([email protected])
This file is a part of the PvPGN Project http://pvpgn.pro
Licensed under the same terms as Lua itself.
]]--


-- Get count of all online users
function users_get_count()
local count = 0
for id,username in pairs(api.server_get_users()) do
count = count + 1
end
return count
end

-- Get count of all server account
function accounts_get_count()
local count = 0
for id,username in pairs(api.server_get_users(true)) do
count = count + 1
end
return count
end

Loading

0 comments on commit ee04fdd

Please sign in to comment.