Add a "simulate lobby activity" plugin
This is the first step towards creating artificial load and testing if the GUI2 lobby still performs well under load. I also implemented ability to leave the game in the GUI2 MP staging dialog. Previously the server continued to believe that the player remains in the game when he/she closed the MP staging dialog.
This commit is contained in:
parent
b3dc6ac265
commit
296902d426
5 changed files with 100 additions and 1 deletions
74
simulate-lobby-activity.lua
Normal file
74
simulate-lobby-activity.lua
Normal file
|
@ -0,0 +1,74 @@
|
|||
-- simulate-lobby-activity.lua --
|
||||
-- Goes to the MP lobby and chats and creates and leaves games forever. --
|
||||
|
||||
local function create_game(context)
|
||||
local events, info
|
||||
|
||||
context.create({})
|
||||
|
||||
repeat
|
||||
events, context, info = coroutine.yield()
|
||||
until info.name == "Multiplayer Create"
|
||||
|
||||
context.select_type({type = "scenario"})
|
||||
local s = info.find_level({id = "test1"})
|
||||
context.select_level({index = s.index})
|
||||
context.set_name({name = tostring(math.random(999999))})
|
||||
context.update_settings({registered_users = false})
|
||||
|
||||
events, context, info = coroutine.yield()
|
||||
|
||||
context.create({})
|
||||
end
|
||||
|
||||
return function()
|
||||
local events, context, info
|
||||
|
||||
wesnoth.preferences.new_lobby = true
|
||||
|
||||
repeat
|
||||
events, context, info = coroutine.yield()
|
||||
until info.name == "titlescreen" or info.name == "Multiplayer Lobby"
|
||||
|
||||
while info.name == "titlescreen" do
|
||||
context.play_multiplayer({})
|
||||
events, context, info = coroutine.yield()
|
||||
end
|
||||
|
||||
repeat
|
||||
events, context, info = coroutine.yield()
|
||||
until info.name == "Multiplayer Lobby"
|
||||
|
||||
-- Reached the lobby. Random delay before we start actually simulating activity.
|
||||
-- This is here to avoid a situation where activity arrives in bursts after a script
|
||||
-- has launched, say, 100 copies of Wesnoth at the same time.
|
||||
wesnoth.delay(math.random(15000))
|
||||
|
||||
events, context, info = coroutine.yield()
|
||||
|
||||
local in_staging = false
|
||||
|
||||
while true do
|
||||
if math.random() > 0.1 then
|
||||
-- chat message
|
||||
local messages = {"asdf", "qwerty", "zxc"}
|
||||
context.chat({message = messages[math.random(#messages)]})
|
||||
else
|
||||
-- toggle between creating a game and leaving it
|
||||
if not in_staging then
|
||||
create_game(context)
|
||||
in_staging = true
|
||||
else
|
||||
repeat
|
||||
context.quit({})
|
||||
events, context, info = coroutine.yield()
|
||||
until info.name == "Multiplayer Lobby"
|
||||
in_staging = false
|
||||
end
|
||||
end
|
||||
|
||||
wesnoth.delay(15000)
|
||||
|
||||
events, context, info = coroutine.yield()
|
||||
end
|
||||
end
|
|
@ -609,6 +609,13 @@ void connect_engine::start_game_commandline(
|
|||
send_to_server(config("start_game"));
|
||||
}
|
||||
|
||||
void connect_engine::leave_game()
|
||||
{
|
||||
DBG_MP << "leaving the game" << std::endl;
|
||||
|
||||
send_to_server(config("leave_game"));
|
||||
}
|
||||
|
||||
std::pair<bool, bool> connect_engine::process_network_data(const config& data)
|
||||
{
|
||||
std::pair<bool, bool> result(std::make_pair(false, true));
|
||||
|
|
|
@ -71,6 +71,8 @@ public:
|
|||
void start_game();
|
||||
void start_game_commandline(const commandline_options& cmdline_opts);
|
||||
|
||||
void leave_game();
|
||||
|
||||
// Return pair first element specifies whether to leave the game
|
||||
// and second element whether to silently update UI.
|
||||
std::pair<bool, bool> process_network_data(const config& data);
|
||||
|
|
|
@ -363,6 +363,9 @@ void tmp_staging::post_show(twindow& window)
|
|||
if(window.get_retval() == twindow::OK) {
|
||||
connect_engine_.start_game();
|
||||
}
|
||||
else {
|
||||
connect_engine_.leave_game();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -49,12 +49,12 @@
|
|||
|
||||
#include "utils/functional.hpp"
|
||||
#include <boost/range/adaptors.hpp>
|
||||
#include "video.hpp"
|
||||
|
||||
#include "lua/lauxlib.h"
|
||||
#include "lua/lua.h"
|
||||
#include "lua/luaconf.h"
|
||||
|
||||
class CVideo;
|
||||
struct lua_State;
|
||||
|
||||
static lg::log_domain log_scripting_lua("scripting/lua");
|
||||
|
@ -90,9 +90,22 @@ static int intf_describe_plugins(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int intf_delay(lua_State* L)
|
||||
{
|
||||
unsigned int delay = static_cast<unsigned int>(luaL_checkint(L, 1));
|
||||
CVideo::delay(delay);
|
||||
return 0;
|
||||
}
|
||||
|
||||
application_lua_kernel::application_lua_kernel(CVideo * ptr)
|
||||
: lua_kernel_base(ptr)
|
||||
{
|
||||
lua_getglobal(mState, "wesnoth");
|
||||
lua_pushcfunction(mState, intf_delay);
|
||||
lua_setfield(mState, -2, "delay");
|
||||
|
||||
lua_settop(mState, 0);
|
||||
|
||||
lua_pushcfunction(mState, &intf_describe_plugins);
|
||||
lua_setglobal(mState, "describe_plugins");
|
||||
lua_settop(mState, 0);
|
||||
|
|
Loading…
Add table
Reference in a new issue