void SimpleServerEvents::OnSetBattleInfo( int battleid, const wxString& param, const wxString& value )
{
    wxLogDebugFunc( param + _T(", ") + value );
    try
    {
        Battle& battle = m_serv.GetBattle( battleid );
		battle.m_script_tags[param] = value;
        wxString key = param;
        if ( key.Left( 5 ) == _T("game/") )
        {
            key = key.AfterFirst( '/' );
            if ( key.Left( 11 ) == _T( "mapoptions/" ) )
            {
                key = key.AfterFirst( '/' );
                battle.CustomBattleOptions().setSingleOption( key,  value, OptionsWrapper::MapOption );
								battle.Update( wxString::Format(_T("%d_%s"), OptionsWrapper::MapOption, key.c_str() ) );
            }
            else if ( key.Left( 11 ) == _T( "modoptions/" ) )
            {
                key = key.AfterFirst( '/' );
								battle.CustomBattleOptions().setSingleOption( key, value, OptionsWrapper::ModOption );
                battle.Update(  wxString::Format(_T("%d_%s"), OptionsWrapper::ModOption,  key.c_str() ) );
            }
            else if ( key.Left( 8 ) == _T( "restrict" ) )
            {
            	OnBattleDisableUnit( battleid, key.AfterFirst(_T('/')), s2l(value) );
            }
            else if ( key.Left( 4 ) == _T( "team" ) && key.Find( _T("startpos") ) != wxNOT_FOUND )
            {
            	 int team = s2l( key.BeforeFirst(_T('/')).Mid( 4 ) );
				 if ( key.Find( _T("startposx") ) != wxNOT_FOUND )
				 {
					 int numusers = battle.GetNumUsers();
					 for ( int i = 0; i < numusers; i++ )
					 {
						 User& usr = battle.GetUser( i );
						 UserBattleStatus& status = usr.BattleStatus();
						 if ( status.team == team )
						 {
							 status.pos.x = s2l( value );
							 battle.OnUserBattleStatusUpdated( usr, status );
						 }
					 }
				 }
				 else if ( key.Find( _T("startposy") ) != wxNOT_FOUND )
				 {
					 int numusers = battle.GetNumUsers();
					 for ( int i = 0; i < numusers; i++ )
					 {
						 User& usr = battle.GetUser( i );
						 UserBattleStatus& status = usr.BattleStatus();
						 if ( status.team == team )
						 {
							 status.pos.y = s2l( value );
							 battle.OnUserBattleStatusUpdated( usr, status );
						 }
					 }
				 }
            }
            else
            {
				battle.CustomBattleOptions().setSingleOption( key,  value, OptionsWrapper::EngineOption );
				battle.Update( wxString::Format(_T("%d_%s"), OptionsWrapper::EngineOption, key.c_str() ) );
            }
        }
    }
    catch (assert_exception) {}
}
void ServerEvents::OnSetBattleInfo(int battleid, const std::string& param, const std::string& value)
{
	slLogDebugFunc("%s, %s", param.c_str(), value.c_str());
	IBattle& battle = m_serv.GetBattle(battleid);
	battle.m_script_tags[param] = value;
	const LSL::StringVector vec = LSL::Util::StringTokenize(param, "/"); //split string by slash

	switch (vec.size()) {
		case 3: { // depth 3
			if (param.find("game/mapoptions") == 0) {
				if (!battle.CustomBattleOptions().setSingleOption(vec[2], value, LSL::Enum::MapOption)) {
					wxLogWarning("OnSetBattleInfo: Couldn't set map option %s", vec[2].c_str());
				}
				return;
			}
			if (param.find("game/modoptions/") == 0) {
				if (!battle.CustomBattleOptions().setSingleOption(vec[2], value, LSL::Enum::ModOption)) {
					wxLogWarning("OnSetBattleInfo: Couldn't set game option %s", vec[2].c_str());
				}
				return;
			}
			if (param.find("game/restrict") == 0) {
				OnBattleDisableUnit(battleid, vec[2], LSL::Util::FromIntString(value));
				return;
			}
			if (param.find("game/") == 0) { //game/team0/startposx=1692.
				int team = -1;
				if (parseTeam(vec[1], team)) {
					const bool xpos = vec[2] == "startposx";
					const bool ypos = vec[2] == "startposy";
					if (xpos || ypos) {
						int numusers = battle.GetNumUsers();
						for (int i = 0; i < numusers; i++) {
							User& usr = battle.GetUser(i);
							UserBattleStatus& status = usr.BattleStatus();
							if (status.team == team) {
								if (xpos) {
									status.pos.x = LSL::Util::FromIntString(value);
								}
								if (ypos) {
									status.pos.y = LSL::Util::FromIntString(value);
								}
								battle.OnUserBattleStatusUpdated(usr, status);
								ui().OnUserBattleStatus(usr);
							}
						}
						return;
					}
				}
			}
			break;
		}
		case 4: { //depth 4
			if (param.find("game/players/") == 0) {
				if (vec[3] == "skill") {
					const std::string nick = vec[2];
					double skill;
					if (parseSkill(value, skill)) {
						battle.OnPlayerTrueskillChanged(nick, skill); //(std::string& nickname, double trueskill_value)
					}
					return;
				}
				if (vec[3] == "skilluncertainty") { //this is ignored
					return;
				}
			}
			break;
		}
		case 2: { //depth 2
			if (param == "game/hosttype") {
				if (battle.m_autohost_manager == nullptr) {
					wxLogWarning("FIXME: battle.m_autohost_manager == nullptr");
					return;
				}
				if (battle.m_autohost_manager->RecognizeAutohost(value)) {
					wxLogInfo("detected %s autohost", value.c_str()); //FIXME: add event for that + add a label?!
				}
				return;
			}
			// i.e. game/startpostype
			battle.CustomBattleOptions().setSingleOption(vec[1], value, LSL::Enum::EngineOption);
			return;
		}
			/*
		//seems unused
		case 1: { //depth 1
			battle.CustomBattleOptions().setSingleOption(vec[0], value, LSL::Enum::EngineOption);
			battle.Update(stdprintf("%d_%s", LSL::Enum::EngineOption, vec[0].c_str()));
			return;
		}
*/
	}
	wxLogWarning("Unhandled SETSCRIPTTAGS: %s=%s", param.c_str(), value.c_str());
}