本文整理汇总了C++中IBattle::GetUser方法的典型用法代码示例。如果您正苦于以下问题:C++ IBattle::GetUser方法的具体用法?C++ IBattle::GetUser怎么用?C++ IBattle::GetUser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IBattle
的用法示例。
在下文中一共展示了IBattle::GetUser方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnUserQuit
void ServerEvents::OnUserQuit(const std::string& nick)
{
slLogDebugFunc("");
try {
User& user = m_serv.GetUser(nick);
IBattle* userbattle = user.GetBattle();
if (userbattle) {
int battleid = userbattle->GetID();
try {
if (&userbattle->GetFounder() == &user) {
for (int i = 0; i < int(userbattle->GetNumUsers()); i++) {
User& battleuser = userbattle->GetUser(i);
OnUserLeftBattle(battleid, battleuser.GetNick());
}
OnBattleClosed(battleid);
} else
OnUserLeftBattle(battleid, user.GetNick());
} catch (...) {
}
}
ui().OnUserOffline(user);
m_serv._RemoveUser(nick);
if (useractions().DoActionOnUser(UserActions::ActNotifLogin, TowxString(nick)))
actNotifBox(SL_MAIN_ICON, TowxString(nick) + _(" just went offline"));
} catch (std::runtime_error& except) {
}
}
示例2: FilterBattle
bool BattleListFilter::FilterBattle(IBattle& battle)
{
if (!m_activ)
return true;
if (m_filter_highlighted->IsChecked() |
m_filter_status_start->IsChecked() |
m_filter_status_locked->IsChecked() |
m_filter_status_pass->IsChecked() |
m_filter_status_full->IsChecked() |
m_filter_status_open->IsChecked()) {
bool bResult = false;
if (m_filter_highlighted->IsChecked()) {
try {
wxString host = TowxString(battle.GetFounder().GetNick());
bResult = useractions().DoActionOnUser(UserActions::ActHighlight, host);
if (!bResult)
for (unsigned int i = 0; i < battle.GetNumUsers(); ++i) {
wxString name = TowxString(battle.GetUser(i).GetNick());
if (useractions().DoActionOnUser(UserActions::ActHighlight, name)) {
bResult = true;
break;
}
}
} catch (...) {
}
}
//Battle Status Check
if (m_filter_status_start->GetValue())
bResult |= battle.GetInGame();
if (m_filter_status_locked->GetValue())
bResult |= battle.IsLocked();
if (m_filter_status_pass->GetValue())
bResult |= battle.IsPassworded();
if (m_filter_status_full->GetValue())
bResult |= battle.IsFull();
if (m_filter_status_open->GetValue())
bResult |= (!battle.IsPassworded() && !battle.IsLocked() && !battle.GetInGame() && !battle.IsFull());
if (bResult == false)
return false;
}
//Rank Check
/** @fixme Is `nonsenserank' useful, or can it be removed? Why is
* it here in the first place?
*/
/* `Nonsense', in this context, apparently means that the battle
* requires rank 100, exactly, AND we're filtering for values less
* than some number.
*/
bool nonsenserank = (m_filter_rank_mode == BUTTON_MODE_SMALLER) && (battle.GetRankNeeded() == 100);
if (m_filter_rank_choice_value != -1 /* don't have "all" selected */
&& !nonsenserank /* Nonsensical `nonsenserank' flag isn't set. */
&& !_IntCompare(battle.GetRankNeeded(), m_filter_rank_choice_value, m_filter_rank_mode))
return false;
//Player Check
if ((m_filter_player_choice_value != -1) && !_IntCompare(battle.GetNumUsers() - battle.GetSpectators(), m_filter_player_choice_value, m_filter_player_mode))
return false;
//MaxPlayer Check
if ((m_filter_maxplayer_choice_value != -1) && !_IntCompare(battle.GetMaxPlayers(), m_filter_maxplayer_choice_value, m_filter_maxplayer_mode))
return false;
//Spectator Check
if ((m_filter_spectator_choice_value != -1) && !_IntCompare(battle.GetSpectators(), m_filter_spectator_choice_value, m_filter_spectator_mode))
return false;
//Only Maps i have Check
if (m_filter_map_show->GetValue() && !battle.MapExists())
return false;
//Only Mods i have Check
if (m_filter_mod_show->GetValue() && !battle.GameExists())
return false;
//Strings Plain Text & RegEx Check (Case insensitiv)
//Description:
if (!StringMatches(TowxString(battle.GetDescription()),
m_filter_description_edit->GetValue(),
m_filter_description_expression))
return false;
//Host:
try { //!TODO
if (!StringMatches(TowxString(battle.GetFounder().GetNick()),
m_filter_host_edit->GetValue(),
m_filter_host_expression))
//.........这里部分代码省略.........
示例3: WriteScriptTxt
wxString Spring::WriteScriptTxt( IBattle& battle ) const
{
wxLogMessage(_T("0 WriteScriptTxt called "));
wxString ret;
TDFWriter tdf(ret);
// Start generating the script.
tdf.EnterSection( _T("GAME") );
tdf.Append( _T("HostIP"), battle.GetHostIp() );
if ( battle.IsFounderMe() )
{
if ( battle.GetNatType() == NAT_Hole_punching ) tdf.Append( _T("HostPort"), battle.GetMyInternalUdpSourcePort() );
else tdf.Append(_T("HostPort"), battle.GetHostPort() );
}
else
{
tdf.Append( _T("HostPort"), battle.GetHostPort() );
if ( battle.GetNatType() == NAT_Hole_punching )
{
tdf.Append( _T("SourcePort"), battle.GetMyInternalUdpSourcePort() );
}
else if ( sett().GetClientPort() != 0)
{
tdf.Append( _T("SourcePort"), sett().GetClientPort() ); /// this allows to play with broken router by setting SourcePort to some forwarded port.
}
}
tdf.Append( _T("IsHost"), battle.IsFounderMe() );
tdf.Append(_T("MyPlayerName"), battle.GetMe().GetNick() );
if ( !battle.IsFounderMe() )
{
tdf.LeaveSection();
return ret;
}
/**********************************************************************************
Host-only section
**********************************************************************************/
tdf.AppendLineBreak();
tdf.Append(_T("ModHash"), battle.LoadMod().hash );
tdf.Append(_T("MapHash"), battle.LoadMap().hash );
tdf.Append( _T("Mapname"), battle.GetHostMapName() );
tdf.Append( _T("GameType"), battle.GetHostModName() );
tdf.AppendLineBreak();
switch ( battle.GetBattleType() )
{
case BT_Played: break;
case BT_Replay:
{
wxString path = battle.GetPlayBackFilePath();
if ( path.Find(_T("/")) != wxNOT_FOUND ) path.BeforeLast(_T('/'));
tdf.Append( _T("DemoFile"), path );
tdf.AppendLineBreak();
break;
}
case BT_Savegame:
{
wxString path = battle.GetPlayBackFilePath();
if ( path.Find(_T("/")) != wxNOT_FOUND ) path.BeforeLast(_T('/'));
tdf.Append( _T("Savefile"), path );
tdf.AppendLineBreak();
break;
}
default:
wxLogDebugFunc( _T("") ); break;
}
long startpostype;
battle.CustomBattleOptions().getSingleValue( _T("startpostype"), OptionsWrapper::EngineOption ).ToLong( &startpostype );
std::vector<StartPos> remap_positions;
if ( battle.IsProxy() && ( startpostype != IBattle::ST_Pick ) && ( startpostype != IBattle::ST_Choose ) )
{
std::set<int> parsedteams;
unsigned int NumUsers = battle.GetNumUsers();
unsigned int NumTeams = 0;
for ( unsigned int i = 0; i < NumUsers; i++ )
{
User& usr = battle.GetUser( i );
UserBattleStatus& status = usr.BattleStatus();
if ( status.spectator ) continue;
if ( parsedteams.find( status.team ) != parsedteams.end() ) continue; // skip duplicates
parsedteams.insert( status.team );
NumTeams++;
}
MapInfo infos = battle.LoadMap().info;
unsigned int nummapstartpositions = infos.positions.size();
unsigned int copysize = std::min( nummapstartpositions, NumTeams );
remap_positions = std::vector<StartPos> ( infos.positions.begin(), infos.positions.begin() + copysize ); // only add the first x positions
//.........这里部分代码省略.........
示例4: WriteScriptTxt
wxString Spring::WriteScriptTxt( IBattle& battle ) const
{
wxLogMessage(_T("0 WriteScriptTxt called "));
std::stringstream ret;
LSL::TDF::TDFWriter tdf(ret);
// Start generating the script.
tdf.EnterSection("GAME");
if ( battle.IsFounderMe() ) {
tdf.Append("HostIP", ""); //Listen on all addresses for connections when hosting
if ( battle.GetNatType() == NAT_Hole_punching ) tdf.Append("HostPort", battle.GetMyInternalUdpSourcePort() );
else tdf.Append("HostPort", battle.GetHostPort() );
} else {
tdf.Append("HostIP", battle.GetHostIp() );
tdf.Append("HostPort", battle.GetHostPort() );
if ( battle.GetNatType() == NAT_Hole_punching ) {
tdf.Append("SourcePort", battle.GetMyInternalUdpSourcePort() );
} else if ( sett().GetClientPort() != 0) {
tdf.Append("SourcePort", sett().GetClientPort() ); /// this allows to play with broken router by setting SourcePort to some forwarded port.
}
}
tdf.Append("IsHost", battle.IsFounderMe() );
User& me = battle.GetMe();
tdf.Append("MyPlayerName", me.GetNick());
if ( !me.BattleStatus().scriptPassword.empty() ) {
tdf.Append("MyPasswd", me.BattleStatus().scriptPassword);
}
if ( !battle.IsFounderMe() ) {
tdf.LeaveSection();
return TowxString(ret.str());
}
/**********************************************************************************
Host-only section
**********************************************************************************/
tdf.AppendLineBreak();
tdf.Append("ModHash", battle.LoadMod().hash);
tdf.Append("MapHash", battle.LoadMap().hash);
tdf.Append("Mapname", battle.GetHostMapName());
tdf.Append("GameType", battle.GetHostModName());
tdf.AppendLineBreak();
switch ( battle.GetBattleType() ) {
case BT_Played:
break;
case BT_Replay: {
wxString path = TowxString(battle.GetPlayBackFilePath());
if ( path.Find(_T("/")) != wxNOT_FOUND ) path.BeforeLast(_T('/'));
tdf.Append("DemoFile", STD_STRING(path));
tdf.AppendLineBreak();
break;
}
case BT_Savegame: {
wxString path = TowxString(battle.GetPlayBackFilePath());
if ( path.Find(_T("/")) != wxNOT_FOUND ) path.BeforeLast(_T('/'));
tdf.Append("Savefile", STD_STRING(path));
tdf.AppendLineBreak();
break;
}
default:
slLogDebugFunc("");
break;
}
const long startpostype = LSL::Util::FromString<long>(
battle.CustomBattleOptions().getSingleValue("startpostype", LSL::Enum::EngineOption ));
std::vector<LSL::StartPos> remap_positions;
if ( battle.IsProxy() && ( startpostype != IBattle::ST_Pick ) && ( startpostype != IBattle::ST_Choose ) ) {
std::set<int> parsedteams;
unsigned int NumUsers = battle.GetNumUsers();
unsigned int NumTeams = 0;
for ( unsigned int i = 0; i < NumUsers; i++ ) {
User& usr = battle.GetUser( i );
UserBattleStatus& status = usr.BattleStatus();
if ( status.spectator ) continue;
if ( parsedteams.find( status.team ) != parsedteams.end() ) continue; // skip duplicates
parsedteams.insert( status.team );
NumTeams++;
}
LSL::MapInfo infos = battle.LoadMap().info;
unsigned int nummapstartpositions = infos.positions.size();
unsigned int copysize = std::min( nummapstartpositions, NumTeams );
remap_positions = std::vector<LSL::StartPos> ( infos.positions.begin(), infos.positions.begin() + copysize ); // only add the first x positions
if ( startpostype == IBattle::ST_Random ) {
std::random_shuffle( remap_positions.begin(), remap_positions.end() ); // shuffle the positions
}
//.........这里部分代码省略.........