Merge branch 'master' of git://github.com/GreYFoXGTi/DDRace

This commit is contained in:
btd 2010-11-05 14:57:15 +03:00
commit a156d15bd1
14 changed files with 155 additions and 285 deletions

View file

@ -1961,75 +1961,10 @@ void CClient::RegisterCommands()
m_pConsole->Register("reload", "", CFGFLAG_SERVER, 0, 0, "Reload the map", 0);
m_pConsole->Register("login", "?s", CFGFLAG_SERVER, 0, 0, "Allows you access to rcon if no password is given, or changes your level if a password is given", -1);
m_pConsole->Register("auth", "?s", CFGFLAG_SERVER, 0, 0, "Allows you access to rcon if no password is given, or changes your level if a password is given", -1);
m_pConsole->Register("kill_pl", "i", CFGFLAG_SERVER, 0, 0, "Kills player i and announces the kill", 2);
m_pConsole->Register("logout", "?i", CFGFLAG_SERVER, 0, 0, "If you are a helper or didn't specify [i] it logs you out, otherwise it logs player i out", 0);
m_pConsole->Register("helper", "i", CFGFLAG_SERVER, 0, 0, "Authenticates player i to the Level of 1", 2);
m_pConsole->Register("moder", "i", CFGFLAG_SERVER, 0, 0, "Authenticates player i to the Level of 2", 3);
m_pConsole->Register("admin", "i", CFGFLAG_SERVER, 0, 0, "Authenticates player i to the Level of 3 (CAUTION: Irreversible, once he is an admin you can't control him)", 3);
m_pConsole->Register("mute", "ii", CFGFLAG_SERVER, 0, 0, "Mutes player i1 for i2 seconds", 2);
m_pConsole->Register("vote", "r", CFGFLAG_SERVER, 0, 0, "Forces the current vote to result in r (Yes/No)", 3);
m_pConsole->Register("invis_me", "", CFGFLAG_SERVER, 0, 0, "Makes you invisible", 1);
m_pConsole->Register("vis_me", "", CFGFLAG_SERVER, 0, 0, "Makes you visible again", 1);
m_pConsole->Register("invis", "i", CFGFLAG_SERVER, 0, 0, "Makes player i invisible", 2);
m_pConsole->Register("vis", "i", CFGFLAG_SERVER, 0, 0, "Makes player i visible again", 2);
m_pConsole->Register("timerstop", "i", CFGFLAG_SERVER, 0, 0, "Stops the timer of player i", 2);
m_pConsole->Register("timerstart", "i", CFGFLAG_SERVER, 0, 0, "Starts the timer of player i", 2);
m_pConsole->Register("timerrestart", "i", CFGFLAG_SERVER, 0, 0, "Sets the timer of player i to 0 and starts it", 2);
m_pConsole->Register("timerzero", "i", CFGFLAG_SERVER, 0, 0, "Sets the timer of player i to 0 and stops it", 2);
m_pConsole->Register("tele", "ii", CFGFLAG_SERVER, 0, 0, "Teleports player i1 to player i2", 2);
m_pConsole->Register("freeze", "i?i", CFGFLAG_SERVER, 0, 0, "Freezes player i1 for i2 seconds (infinity by default)", 2);
m_pConsole->Register("unfreeze", "i", CFGFLAG_SERVER, 0, 0, "Unfreezes player i", 2);
m_pConsole->Register("shotgun", "i", CFGFLAG_SERVER, 0, 0, "Gives a shotgun to player i", 2);
m_pConsole->Register("shotgun_me", "", CFGFLAG_SERVER, 0, 0, "Gives shotgun to yourself", 1);
m_pConsole->Register("grenade", "i", CFGFLAG_SERVER, 0, 0, "Gives a grenade launcher to player i", 2);
m_pConsole->Register("grenade_me", "", CFGFLAG_SERVER, 0, 0, "Gives grenade launcher to yourself", 1);
m_pConsole->Register("rifle", "i", CFGFLAG_SERVER, 0, 0, "Gives a lasergun to player i", 2);
m_pConsole->Register("rifle_me", "", CFGFLAG_SERVER, 0, 0, "Gives lasergun to yourself", 1);
m_pConsole->Register("weapons", "i", CFGFLAG_SERVER, 0, 0, "Gives all weapons to player i", 2);
m_pConsole->Register("weapons_me", "", CFGFLAG_SERVER, 0, 0, "Gives all weapons to yourself", 1);
m_pConsole->Register("unshotgun", "i", CFGFLAG_SERVER, 0, 0, "Takes a shotgun from player i", 2);
m_pConsole->Register("unshotgun_me", "", CFGFLAG_SERVER, 0, 0, "Takes shotgun from yourself", 1);
m_pConsole->Register("ungrenade", "i", CFGFLAG_SERVER, 0, 0, "Takes a grenade launcher from player i", 2);
m_pConsole->Register("ungrenade_me", "", CFGFLAG_SERVER, 0, 0, "Takes grenade launcher from yourself", 1);
m_pConsole->Register("unrifle", "i", CFGFLAG_SERVER, 0, 0, "Takes a rifle from player i", 2);
m_pConsole->Register("unrifle_me", "", CFGFLAG_SERVER, 0, 0, "Takes rifle from yourself", 1);
m_pConsole->Register("unweapons", "i", CFGFLAG_SERVER, 0, 0, "Takes all weapons from player i", 2);
m_pConsole->Register("unweapons_me", "", CFGFLAG_SERVER, 0, 0, "Takes all weapons from yourself", 1);
m_pConsole->Register("ninja", "i", CFGFLAG_SERVER, 0, 0, "Makes player i a ninja", 2);
m_pConsole->Register("ninja_me", "", CFGFLAG_SERVER, 0, 0, "Makes yourself a ninja", 1);
m_pConsole->Register("hammer_me", "i", CFGFLAG_SERVER, 0, 0, "Sets your hammer power to i", 1);
m_pConsole->Register("hammer", "ii", CFGFLAG_SERVER, 0, 0, "Sets the hammer power of player i1 to i2", 2);
m_pConsole->Register("super", "i", CFGFLAG_SERVER, 0, 0, "Makes player i super", 2);
m_pConsole->Register("unsuper", "i", CFGFLAG_SERVER, 0, 0, "Removes super from player i", 2);
m_pConsole->Register("super_me", "", CFGFLAG_SERVER, 0, 0, "Makes yourself super", 1);
m_pConsole->Register("unsuper_me", "", CFGFLAG_SERVER, 0, 0, "Removes super from yourself", 1);
m_pConsole->Register("left", "?i", CFGFLAG_SERVER, 0, 0, "Makes you or player i move 1 tile left", 1);
m_pConsole->Register("right", "?i", CFGFLAG_SERVER, 0, 0, "Makes you or player i move 1 tile right", 1);
m_pConsole->Register("up", "?i", CFGFLAG_SERVER, 0, 0, "Makes you or player i move 1 tile up", 1);
m_pConsole->Register("down", "?i", CFGFLAG_SERVER, 0, 0, "Makes you or player i move 1 tile down", 1);
m_pConsole->Register("addvote", "r", CFGFLAG_SERVER, 0, 0, "Adds a vote entry to the clients", 4);
m_pConsole->Register("broadtime", "", CFGFLAG_SERVER, 0, 0, "Toggles Showing the time string in race", -1);
m_pConsole->Register("cmdlist", "", CFGFLAG_SERVER, 0, 0, "Shows the list of all commands", -1);
m_pConsole->Register("credits", "", CFGFLAG_SERVER, 0, 0, "Shows the credits of the DDRace mod", -1);
m_pConsole->Register("emote", "?s?i", CFGFLAG_SERVER, 0, 0, "Sets your tee's eye emote", -1);
m_pConsole->Register("broadmsg", "", CFGFLAG_SERVER, 0, 0, "Toggle Showing the Server's Broadcast message during race", -1);
m_pConsole->Register("eyeemote", "", CFGFLAG_SERVER, 0, 0, "Toggles whether you automatically use eyeemotes with standard emotes", -1);
m_pConsole->Register("flags", "", CFGFLAG_SERVER, 0, 0, "Shows gameplay information for this server", -1);
m_pConsole->Register("fly", "", CFGFLAG_SERVER, 0, 0, "Toggles whether you fly by pressing jump", 1);
m_pConsole->Register("help", "?r", CFGFLAG_SERVER, 0, 0, "Helps you with commands", -1);
m_pConsole->Register("info", "", CFGFLAG_SERVER, 0, 0, "Shows info about this server", -1);
m_pConsole->Register("kill", "", CFGFLAG_SERVER, 0, 0, "Kills you", -1);
m_pConsole->Register("me", "s", CFGFLAG_SERVER, 0, 0, "", -1); // TODO: add help text, cause idk how to describe this (heinrich5991)
m_pConsole->Register("pause", "", CFGFLAG_SERVER, 0, 0, "If enabled on this server it pauses the game for you", -1);
m_pConsole->Register("rank", "?r", CFGFLAG_SERVER, 0, 0, "Shows either your rank or the rank of the given player", -1);
m_pConsole->Register("rules", "", CFGFLAG_SERVER, 0, 0, "Shows the rules of this server", -1);
m_pConsole->Register("team", "?i", CFGFLAG_SERVER, 0, 0, "Lets you join the specified team", -1);
m_pConsole->Register("top5", "?i", CFGFLAG_SERVER, 0, 0, "Shows the top 5 from the 1st, or starting at the specified number", -1);
m_pConsole->Register("addweapon", "i?i", CFGFLAG_SERVER, 0, 0, "First optional parameter is client id, next parameter is weapon (all = -1, hammer = 0, gun = 1, shotgun = 2, grenade = 3, rifle = 4, ninja = 5)", 1);
m_pConsole->Register("removeweapon", "i?i", CFGFLAG_SERVER, 0, 0, "First optional parameter is client id, next parameter is weapon (all = -1, hammer = 0, gun = 1, shotgun = 2, grenade = 3, rifle = 4)", 1);
m_pConsole->Register("move", "ii?i", CFGFLAG_SERVER, 0, 0, "First optional parameter is client id, next parameters are x-axis change and y-axis change (1 = 1 tile)", 1);
m_pConsole->Register("move_raw", "ii?i", CFGFLAG_SERVER, 0, 0, "First optional parameter is client id, next parameters are x-axis change and y-axis change (1 = 1 pixel)", 1);
#define CONSOLE_COMMAND(name, params, flags, callback, userdata, help, level) m_pConsole->Register(name, params, flags, 0, 0, help, level);
#include <game/ddracecommands.h>
m_pConsole->Register("quit", "", CFGFLAG_CLIENT|CFGFLAG_STORE, Con_Quit, this, "Quit Teeworlds", 0);
m_pConsole->Register("exit", "", CFGFLAG_CLIENT|CFGFLAG_STORE, Con_Quit, this, "Quit Teeworlds", 0);

View file

@ -122,7 +122,6 @@ MACRO_CONFIG_INT(SvSuicidePenalty, sv_suicide_penalty,0,0,9999,CFGFLAG_SERVER, "
MACRO_CONFIG_INT(SvVotePercentage, sv_vote_percentage, 50, 1, 100, CFGFLAG_SERVER, "The percent of people that need to agree or deny for the vote to succeed/fail", 3)
MACRO_CONFIG_INT(SvShotgunBulletSound, sv_shotgun_bullet_sound, 0, 0, 1, CFGFLAG_SERVER, "Crazy shotgun bullet sound on/off", 3)
MACRO_CONFIG_INT(SvScoreIP, sv_score_ip, 0, 0, 0, CFGFLAG_SERVER, "Wheather to save also the IP in the score file", 3)
MACRO_CONFIG_INT(SvCheckpointSave, sv_checkpoint_save, 1, 0, 1, CFGFLAG_SERVER, "Whether to save checkpoint times to the score file", 3)
MACRO_CONFIG_STR(SvScoreFolder, sv_score_folder, 32, "records", CFGFLAG_SERVER, "Folder to save score files to", 3)

View file

@ -393,9 +393,6 @@ void CGameClient::OnReset()
for(int i = 0; i < m_All.m_Num; i++)
m_All.m_paComponents[i]->OnReset();
m_Teams.Reset();
Layers()->Dest();
Collision()->Dest();
m_DDRaceMsgSent = false;
}

View file

@ -41,6 +41,8 @@ void CCollision::Dest()
void CCollision::Init(class CLayers *pLayers)
{
if(m_pLayers) m_pLayers->Dest();
Dest();
m_pLayers = pLayers;
m_Width = m_pLayers->GameLayer()->m_Width;
m_Height = m_pLayers->GameLayer()->m_Height;
@ -245,6 +247,11 @@ int CCollision::GetTile(int x, int y)
{
int nx = clamp(x/32, 0, m_Width-1);
int ny = clamp(y/32, 0, m_Height-1);
if(!m_pTiles || ny < 0 || nx < 0)
{
//dbg_msg("Collision","Something is terribly wrong, !m_pTiles %d, ny %d, ny %d", !m_pTiles, ny, ny);
return 0;
}
/*dbg_msg("GetTile","m_Index %d",m_pTiles[ny*m_Width+nx].m_Index);//Remove */
if(m_pTiles[ny*m_Width+nx].m_Index == COLFLAG_SOLID
|| m_pTiles[ny*m_Width+nx].m_Index == (COLFLAG_SOLID|COLFLAG_NOHOOK)

79
src/game/ddracecommands.h Normal file
View file

@ -0,0 +1,79 @@
#ifndef GAME_SERVER_DDRACECOMMANDS_H
#define GAME_SERVER_DDRACECOMMANDS_H
#undef GAME_SERVER_DDRACECOMMANDS_H // this file can be included several times
#ifndef CONSOLE_COMMAND
#define CONSOLE_COMMAND(name, params, flags, callback, userdata, help, level)
#endif
CONSOLE_COMMAND("clear_votes", "", CFGFLAG_SERVER, ConClearVotes, this, "Clears the vote list", 4)
CONSOLE_COMMAND("kill_pl", "i", CFGFLAG_SERVER, ConKillPlayer, this, "Kills player i and announces the kill", 2)
CONSOLE_COMMAND("logout", "?i", CFGFLAG_SERVER, ConLogOut, this, "If you are a helper or didn't specify [i] it logs you out, otherwise it logs player i out", 0)
CONSOLE_COMMAND("helper", "i", CFGFLAG_SERVER, ConSetlvl1, this, "Authenticates player i to the Level of 1", 2)
CONSOLE_COMMAND("moder", "i", CFGFLAG_SERVER, ConSetlvl2, this, "Authenticates player i to the Level of 2", 3)
CONSOLE_COMMAND("admin", "i", CFGFLAG_SERVER, ConSetlvl3, this, "Authenticates player i to the Level of 3 (CAUTION: Irreversible, once he is an admin you can't control him)", 3)
CONSOLE_COMMAND("mute", "ii", CFGFLAG_SERVER, ConMute, this, "Mutes player i1 for i2 seconds", 2)
CONSOLE_COMMAND("invis_me", "", CFGFLAG_SERVER, ConInvisMe, this, "Makes you invisible", 1)
CONSOLE_COMMAND("vis_me", "", CFGFLAG_SERVER, ConVisMe, this, "Makes you visible again", 1)
CONSOLE_COMMAND("invis", "i", CFGFLAG_SERVER, ConInvis, this, "Makes player i invisible", 2)
CONSOLE_COMMAND("vis", "i", CFGFLAG_SERVER, ConVis, this, "Makes player i visible again", 2)
CONSOLE_COMMAND("timerstop", "i", CFGFLAG_SERVER, ConTimerStop, this, "Stops the timer of player i", 2)
CONSOLE_COMMAND("timerstart", "i", CFGFLAG_SERVER, ConTimerStart, this, "Starts the timer of player i", 2)
CONSOLE_COMMAND("timerrestart", "i", CFGFLAG_SERVER, ConTimerReStart, this, "Sets the timer of player i to 0 and starts it", 2)
CONSOLE_COMMAND("timerzero", "i", CFGFLAG_SERVER, ConTimerZero, this, "Sets the timer of player i to 0 and stops it", 2)
CONSOLE_COMMAND("tele", "ii", CFGFLAG_SERVER, ConTeleport, this, "Teleports player i1 to player i2", 2)
CONSOLE_COMMAND("freeze", "i?i", CFGFLAG_SERVER, ConFreeze, this, "Freezes player i1 for i2 seconds (infinity by default)", 2)
CONSOLE_COMMAND("unfreeze", "i", CFGFLAG_SERVER, ConUnFreeze, this, "Unfreezes player i", 2)
CONSOLE_COMMAND("addweapon", "i?i", CFGFLAG_SERVER, ConAddWeapon, this, "First optional parameter is client id, next parameter is weapon (all = -1, hammer = 0, gun = 1, shotgun = 2, grenade = 3, rifle = 4, ninja = 5)", 1)
CONSOLE_COMMAND("removeweapon", "i?i", CFGFLAG_SERVER, ConRemoveWeapon, this, "First optional parameter is client id, next parameter is weapon (all = -1, hammer = 0, gun = 1, shotgun = 2, grenade = 3, rifle = 4)", 1)
CONSOLE_COMMAND("shotgun", "i", CFGFLAG_SERVER, ConShotgun, this, "Gives a shotgun to player i", 2)
CONSOLE_COMMAND("shotgun_me", "", CFGFLAG_SERVER, ConShotgunMe, this, "Gives shotgun to yourself", 1)
CONSOLE_COMMAND("grenade", "i", CFGFLAG_SERVER, ConGrenade, this, "Gives a grenade launcher to player i", 2)
CONSOLE_COMMAND("grenade_me", "", CFGFLAG_SERVER, ConGrenadeMe, this, "Gives grenade launcher to yourself", 1)
CONSOLE_COMMAND("rifle", "i", CFGFLAG_SERVER, ConRifle, this, "Gives a rifle to player i", 2)
CONSOLE_COMMAND("rifle_me", "", CFGFLAG_SERVER, ConRifleMe, this, "Gives rifle to yourself", 1)
CONSOLE_COMMAND("weapons", "i", CFGFLAG_SERVER, ConWeapons, this, "Gives all weapons to player i", 2)
CONSOLE_COMMAND("weapons_me", "", CFGFLAG_SERVER, ConWeaponsMe, this, "Gives all weapons to yourself", 1)
CONSOLE_COMMAND("unshotgun", "i", CFGFLAG_SERVER, ConUnShotgun, this, "Takes a shotgun from player i", 2)
CONSOLE_COMMAND("unshotgun_me", "", CFGFLAG_SERVER, ConUnShotgunMe, this, "Takes shotgun from yourself", 1)
CONSOLE_COMMAND("ungrenade", "i", CFGFLAG_SERVER, ConUnGrenade, this, "Takes a grenade launcher from player i", 2)
CONSOLE_COMMAND("ungrenade_me", "", CFGFLAG_SERVER, ConUnGrenadeMe, this, "Takes grenade launcher from yourself", 1)
CONSOLE_COMMAND("unrifle", "i", CFGFLAG_SERVER, ConUnRifle, this, "Takes a rifle from player i", 2)
CONSOLE_COMMAND("unrifle_me", "", CFGFLAG_SERVER, ConUnRifleMe, this, "Takes rifle from yourself", 1)
CONSOLE_COMMAND("unweapons", "i", CFGFLAG_SERVER, ConUnWeapons, this, "Takes all weapons from player i", 2)
CONSOLE_COMMAND("unweapons_me", "", CFGFLAG_SERVER, ConUnWeaponsMe, this, "Takes all weapons from yourself", 1)
CONSOLE_COMMAND("ninja", "i", CFGFLAG_SERVER, ConNinja, this, "Makes player i a ninja", 2)
CONSOLE_COMMAND("ninja_me", "", CFGFLAG_SERVER, ConNinjaMe, this, "Makes yourself a ninja", 1)
CONSOLE_COMMAND("hammer_me", "i", CFGFLAG_SERVER, ConHammerMe, this, "Sets your hammer power to i", 1)
CONSOLE_COMMAND("hammer", "ii", CFGFLAG_SERVER, ConHammer, this, "Sets the hammer power of player i1 to i2", 2)
CONSOLE_COMMAND("super", "i", CFGFLAG_SERVER, ConSuper, this, "Makes player i super", 2)
CONSOLE_COMMAND("unsuper", "i", CFGFLAG_SERVER, ConUnSuper, this, "Removes super from player i", 2)
CONSOLE_COMMAND("super_me", "", CFGFLAG_SERVER, ConSuperMe, this, "Makes yourself super", 1)
CONSOLE_COMMAND("unsuper_me", "", CFGFLAG_SERVER, ConUnSuperMe, this, "Removes super from yourself", 1)
CONSOLE_COMMAND("left", "?i", CFGFLAG_SERVER, ConGoLeft, this, "Makes you or player i move 1 tile left", 1)
CONSOLE_COMMAND("right", "?i", CFGFLAG_SERVER, ConGoRight, this, "Makes you or player i move 1 tile right", 1)
CONSOLE_COMMAND("up", "?i", CFGFLAG_SERVER, ConGoUp, this, "Makes you or player i move 1 tile up", 1)
CONSOLE_COMMAND("down", "?i", CFGFLAG_SERVER, ConGoDown, this, "Makes you or player i move 1 tile down", 1)
CONSOLE_COMMAND("move", "ii?i", CFGFLAG_SERVER, ConMove, this, "First optional parameter is client id, next parameters are x-axis change and y-axis change (1 = 1 tile)", 1)
CONSOLE_COMMAND("move_raw", "ii?i", CFGFLAG_SERVER, ConMoveRaw, this, "First optional parameter is client id, next parameters are x-axis change and y-axis change (1 = 1 pixel)", 1)
CONSOLE_COMMAND("broadtime", "", CFGFLAG_SERVER, ConBroadTime, this, "Toggles Showing the time string in race", -1)
CONSOLE_COMMAND("cmdlist", "", CFGFLAG_SERVER, ConCmdList, this, "Shows the list of all commands", -1)
CONSOLE_COMMAND("credits", "", CFGFLAG_SERVER, ConCredits, this, "Shows the credits of the DDRace mod", -1)
CONSOLE_COMMAND("emote", "?s?i", CFGFLAG_SERVER, ConEyeEmote, this, "Sets your tee's eye emote", -1)
CONSOLE_COMMAND("broadmsg", "", CFGFLAG_SERVER, ConToggleBroadcast, this, "Toggle Showing the Server's Broadcast message during race", -1)
CONSOLE_COMMAND("eyeemote", "", CFGFLAG_SERVER, ConEyeEmote, this, "Toggles whether you automatically use eyeemotes with standard emotes", -1)
CONSOLE_COMMAND("flags", "", CFGFLAG_SERVER, ConFlags, this, "Shows gameplay information for this server", -1)
CONSOLE_COMMAND("fly", "", CFGFLAG_SERVER, ConToggleFly, this, "Toggles whether you fly by pressing jump", 1)
CONSOLE_COMMAND("help", "?r", CFGFLAG_SERVER, ConHelp, this, "Helps you with commands", -1)
CONSOLE_COMMAND("info", "", CFGFLAG_SERVER, ConInfo, this, "Shows info about this server", -1)
CONSOLE_COMMAND("kill", "", CFGFLAG_SERVER, ConKill, this, "Kills you", -1)
CONSOLE_COMMAND("me", "r", CFGFLAG_SERVER, ConMe, this, "Like the famous irc commands /me says hi, will display YOURNAME says hi", -1)
CONSOLE_COMMAND("pause", "", CFGFLAG_SERVER, ConTogglePause, this, "If enabled on this server it pauses the game for you", -1)
CONSOLE_COMMAND("rank", "?r", CFGFLAG_SERVER, ConRank, this, "Shows either your rank or the rank of the given player", -1)
CONSOLE_COMMAND("rules", "", CFGFLAG_SERVER, ConRules, this, "Shows the rules of this server", -1)
CONSOLE_COMMAND("team", "?i", CFGFLAG_SERVER, ConJoinTeam, this, "Lets you join the specified team", -1)
CONSOLE_COMMAND("top5", "?i", CFGFLAG_SERVER, ConTop5, this, "Shows the top 5 from the 1st, or starting at the specified number", -1)
#undef CONSOLE_COMMAND
#endif

View file

@ -17,17 +17,10 @@ CLayers::CLayers()
void CLayers::Dest()
{
m_GroupsNum = 0;
m_GroupsStart = 0;
m_LayersNum = 0;
m_LayersStart = 0;
m_pGameGroup = 0;
m_pGameLayer = 0;
m_pTeleLayer = 0;
m_pSpeedupLayer = 0;
m_pFrontLayer = 0;
m_pSwitchLayer = 0;
m_pMap = 0;
}
void CLayers::Init(class IKernel *pKernel)

View file

@ -298,9 +298,15 @@ void CCharacter::FireWeapon()
// check for ammo
if(!m_aWeapons[m_ActiveWeapon].m_Ammo)
{
// 125ms is a magical limit of how fast a human can click
/* // 125ms is a magical limit of how fast a human can click
m_ReloadTimer = 1 * Server()->TickSpeed();
GameServer()->CreateSound(m_Pos, SOUND_PLAYER_PAIN_LONG);
GameServer()->CreateSound(m_Pos, SOUND_PLAYER_PAIN_LONG);*/
// Timerstuff to avoid shrieking orchestra caused by unfreeze-plasma
if(m_PainSoundTimer<=0)
{
m_PainSoundTimer = 1 * Server()->TickSpeed();
GameServer()->CreateSound(m_Pos, SOUND_PLAYER_PAIN_LONG);
}
return;
}
@ -489,6 +495,9 @@ void CCharacter::HandleWeapons()
HandleNinja();
vec2 Direction = normalize(vec2(m_LatestInput.m_TargetX, m_LatestInput.m_TargetY));
// check PainSoundTimer - Hmm, maybe sometimes shrieking can be a weapon too? ;)
if(m_PainSoundTimer>0)
m_PainSoundTimer--;
// check reload timer
if(m_ReloadTimer)
@ -593,7 +602,7 @@ void CCharacter::OnFinish()
char aBuf[128];
m_CpActive=-2;
str_format(aBuf, sizeof(aBuf), "%s finished in: %d minute(s) %5.2f second(s)", Server()->ClientName(m_pPlayer->GetCID()), (int)time/60, time-((int)time/60*60));
if(!g_Config.m_SvHideScore)
if(g_Config.m_SvHideScore)
GameServer()->SendChatTarget(m_pPlayer->GetCID(), aBuf);
else
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf);
@ -601,12 +610,17 @@ void CCharacter::OnFinish()
if(time - pData->m_BestTime < 0)
{
// new record \o/
str_format(aBuf, sizeof(aBuf), "New record: %5.2f second(s) better", time - pData->m_BestTime);
if(!g_Config.m_SvHideScore)
str_format(aBuf, sizeof(aBuf), "New record: %5.2f second(s) better.", fabs(time - pData->m_BestTime));
if(g_Config.m_SvHideScore)
GameServer()->SendChatTarget(m_pPlayer->GetCID(), aBuf);
else
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf);
}
else
{
str_format(aBuf, sizeof(aBuf), "%5.2f second(s) worse, better luck next time.", fabs(pData->m_BestTime - time));
GameServer()->SendChatTarget(m_pPlayer->GetCID(), aBuf);//this is private, sent only to the tee
}
if(!pData->m_BestTime || time < pData->m_BestTime)
{
@ -1265,9 +1279,11 @@ bool CCharacter::UnFreeze()
{
m_aWeapons[i].m_Ammo = -1;
}
if(!m_aWeapons[m_ActiveWeapon].m_Got) m_ActiveWeapon=WEAPON_GUN;
m_FreezeTime=0;
m_FreezeTick=0;
if(!m_aWeapons[m_ActiveWeapon].m_Got)
m_ActiveWeapon = WEAPON_GUN;
m_FreezeTime = 0;
m_FreezeTick = 0;
m_ReloadTimer = 0;
return true;
}
return false;

View file

@ -137,6 +137,7 @@ public:
int m_QueuedWeapon;
int m_ReloadTimer;
int m_PainSoundTimer;
int m_AttackTick;
int m_DamageTaken;

View file

@ -2399,95 +2399,16 @@ void CGameContext::OnConsoleInit()
Console()->Register("say", "r", CFGFLAG_SERVER, ConSay, this, "Sends a server message to all players", 3);
Console()->Register("set_team", "ii", CFGFLAG_SERVER, ConSetTeam, this, "Changes the team of player i1 to team i2", 2);
Console()->Register("addvote", "r", CFGFLAG_SERVER, ConAddVote, this, "Adds a vote entry to the clients", 4);
Console()->Register("clear_votes", "", CFGFLAG_SERVER, ConClearVotes, this, "Clears the vote list", 4);
Console()->Register("tune", "si", CFGFLAG_SERVER, ConTuneParam, this, "Modifies tune parameter s to value i", 4);
Console()->Register("tune_reset", "", CFGFLAG_SERVER, ConTuneReset, this, "Resets all tuning", 4);
Console()->Register("tune_dump", "", CFGFLAG_SERVER, ConTuneDump, this, "Shows all tuning options", 4);
Console()->Register("kill_pl", "i", CFGFLAG_SERVER, ConKillPlayer, this, "Kills player i and announces the kill", 2);
Console()->Register("logout", "?i", CFGFLAG_SERVER, ConLogOut, this, "If you are a helper or didn't specify [i] it logs you out, otherwise it logs player i out", 0);
Console()->Register("helper", "i", CFGFLAG_SERVER, ConSetlvl1, this, "Authenticates player i to the Level of 1", 2);
Console()->Register("moder", "i", CFGFLAG_SERVER, ConSetlvl2, this, "Authenticates player i to the Level of 2", 3);
Console()->Register("admin", "i", CFGFLAG_SERVER, ConSetlvl3, this, "Authenticates player i to the Level of 3 (CAUTION: Irreversible, once he is an admin you can't control him)", 3);
Console()->Register("mute", "ii", CFGFLAG_SERVER, ConMute, this, "Mutes player i1 for i2 seconds", 2);
Console()->Register("vote", "r", CFGFLAG_SERVER, ConVote, this, "Forces the current vote to result in r (Yes/No)", 3);
Console()->Register("invis_me", "", CFGFLAG_SERVER, ConInvisMe, this, "Makes you invisible", 1);
Console()->Register("vis_me", "", CFGFLAG_SERVER, ConVisMe, this, "Makes you visible again", 1);
Console()->Register("invis", "i", CFGFLAG_SERVER, ConInvis, this, "Makes player i invisible", 2);
Console()->Register("vis", "i", CFGFLAG_SERVER, ConVis, this, "Makes player i visible again", 2);
Console()->Register("timerstop", "i", CFGFLAG_SERVER, ConTimerStop, this, "Stops the timer of player i", 2);
Console()->Register("timerstart", "i", CFGFLAG_SERVER, ConTimerStart, this, "Starts the timer of player i", 2);
Console()->Register("timerrestart", "i", CFGFLAG_SERVER, ConTimerReStart, this, "Sets the timer of player i to 0 and starts it", 2);
Console()->Register("timerzero", "i", CFGFLAG_SERVER, ConTimerZero, this, "Sets the timer of player i to 0 and stops it", 2);
Console()->Register("tele", "ii", CFGFLAG_SERVER, ConTeleport, this, "Teleports player i1 to player i2", 2);
Console()->Register("freeze", "i?i", CFGFLAG_SERVER, ConFreeze, this, "Freezes player i1 for i2 seconds (infinity by default)", 2);
Console()->Register("unfreeze", "i", CFGFLAG_SERVER, ConUnFreeze, this, "Unfreezes player i", 2);
Console()->Register("addweapon", "i?i", CFGFLAG_SERVER, ConAddWeapon, this, "First optional parameter is client id, next parameter is weapon (all = -1, hammer = 0, gun = 1, shotgun = 2, grenade = 3, rifle = 4, ninja = 5)", 1);
Console()->Register("removeweapon", "i?i", CFGFLAG_SERVER, ConRemoveWeapon, this, "First optional parameter is client id, next parameter is weapon (all = -1, hammer = 0, gun = 1, shotgun = 2, grenade = 3, rifle = 4)", 1);
Console()->Register("shotgun", "i", CFGFLAG_SERVER, ConShotgun, this, "Gives a shotgun to player i", 2);
Console()->Register("shotgun_me", "", CFGFLAG_SERVER, ConShotgunMe, this, "Gives shotgun to yourself", 1);
Console()->Register("grenade", "i", CFGFLAG_SERVER, ConGrenade, this, "Gives a grenade launcher to player i", 2);
Console()->Register("grenade_me", "", CFGFLAG_SERVER, ConGrenadeMe, this, "Gives grenade launcher to yourself", 1);
Console()->Register("rifle", "i", CFGFLAG_SERVER, ConRifle, this, "Gives a rifle to player i", 2);
Console()->Register("rifle_me", "", CFGFLAG_SERVER, ConRifleMe, this, "Gives rifle to yourself", 1);
Console()->Register("weapons", "i", CFGFLAG_SERVER, ConWeapons, this, "Gives all weapons to player i", 2);
Console()->Register("weapons_me", "", CFGFLAG_SERVER, ConWeaponsMe, this, "Gives all weapons to yourself", 1);
Console()->Register("unshotgun", "i", CFGFLAG_SERVER, ConUnShotgun, this, "Takes a shotgun from player i", 2);
Console()->Register("unshotgun_me", "", CFGFLAG_SERVER, ConUnShotgunMe, this, "Takes shotgun from yourself", 1);
Console()->Register("ungrenade", "i", CFGFLAG_SERVER, ConUnGrenade, this, "Takes a grenade launcher from player i", 2);
Console()->Register("ungrenade_me", "", CFGFLAG_SERVER, ConUnGrenadeMe, this, "Takes grenade launcher from yourself", 1);
Console()->Register("unrifle", "i", CFGFLAG_SERVER, ConUnRifle, this, "Takes a rifle from player i", 2);
Console()->Register("unrifle_me", "", CFGFLAG_SERVER, ConUnRifleMe, this, "Takes rifle from yourself", 1);
Console()->Register("unweapons", "i", CFGFLAG_SERVER, ConUnWeapons, this, "Takes all weapons from player i", 2);
Console()->Register("unweapons_me", "", CFGFLAG_SERVER, ConUnWeaponsMe, this, "Takes all weapons from yourself", 1);
Console()->Register("ninja", "i", CFGFLAG_SERVER, ConNinja, this, "Makes player i a ninja", 2);
Console()->Register("ninja_me", "", CFGFLAG_SERVER, ConNinjaMe, this, "Makes yourself a ninja", 1);
Console()->Register("hammer_me", "i", CFGFLAG_SERVER, ConHammerMe, this, "Sets your hammer power to i", 1);
Console()->Register("hammer", "ii", CFGFLAG_SERVER, ConHammer, this, "Sets the hammer power of player i1 to i2", 2);
Console()->Register("super", "i", CFGFLAG_SERVER, ConSuper, this, "Makes player i super", 2);
Console()->Register("unsuper", "i", CFGFLAG_SERVER, ConUnSuper, this, "Removes super from player i", 2);
Console()->Register("super_me", "", CFGFLAG_SERVER, ConSuperMe, this, "Makes yourself super", 1);
Console()->Register("unsuper_me", "", CFGFLAG_SERVER, ConUnSuperMe, this, "Removes super from yourself", 1);
Console()->Register("left", "?i", CFGFLAG_SERVER, ConGoLeft, this, "Makes you or player i move 1 tile left", 1);
Console()->Register("right", "?i", CFGFLAG_SERVER, ConGoRight, this, "Makes you or player i move 1 tile right", 1);
Console()->Register("up", "?i", CFGFLAG_SERVER, ConGoUp, this, "Makes you or player i move 1 tile up", 1);
Console()->Register("down", "?i", CFGFLAG_SERVER, ConGoDown, this, "Makes you or player i move 1 tile down", 1);
Console()->Register("move", "ii?i", CFGFLAG_SERVER, ConMove, this, "First optional parameter is client id, next parameters are x-axis change and y-axis change (1 = 1 tile)", 1);
Console()->Register("move_raw", "ii?i", CFGFLAG_SERVER, ConMoveRaw, this, "First optional parameter is client id, next parameters are x-axis change and y-axis change (1 = 1 pixel)", 1);
Console()->Register("broadtime", "", CFGFLAG_SERVER, ConBroadTime, this, "Toggles Showing the time string in race", -1);
Console()->Register("cmdlist", "", CFGFLAG_SERVER, ConCmdList, this, "Shows the list of all commands", -1);
Console()->Register("credits", "", CFGFLAG_SERVER, ConCredits, this, "Shows the credits of the DDRace mod", -1);
Console()->Register("emote", "?s?i", CFGFLAG_SERVER, ConEyeEmote, this, "Sets your tee's eye emote", -1);
Console()->Register("broadmsg", "", CFGFLAG_SERVER, ConToggleBroadcast, this, "Toggle Showing the Server's Broadcast message during race", -1);
Console()->Register("eyeemote", "", CFGFLAG_SERVER, ConEyeEmote, this, "Toggles whether you automatically use eyeemotes with standard emotes", -1);
Console()->Register("flags", "", CFGFLAG_SERVER, ConFlags, this, "Shows gameplay information for this server", -1);
Console()->Register("fly", "", CFGFLAG_SERVER, ConToggleFly, this, "Toggles whether you fly by pressing jump", 1);
Console()->Register("help", "?r", CFGFLAG_SERVER, ConHelp, this, "Helps you with commands", -1);
Console()->Register("info", "", CFGFLAG_SERVER, ConInfo, this, "Shows info about this server", -1);
Console()->Register("kill", "", CFGFLAG_SERVER, ConKill, this, "Kills you", -1);
Console()->Register("me", "s", CFGFLAG_SERVER, ConMe, this, "Like the famous irc commands /me says hi, will display YOURNAME says hi", -1);
Console()->Register("pause", "", CFGFLAG_SERVER, ConTogglePause, this, "If enabled on this server it pauses the game for you", -1);
Console()->Register("rank", "?r", CFGFLAG_SERVER, ConRank, this, "Shows either your rank or the rank of the given player", -1);
Console()->Register("rules", "", CFGFLAG_SERVER, ConRules, this, "Shows the rules of this server", -1);
Console()->Register("team", "?i", CFGFLAG_SERVER, ConJoinTeam, this, "Lets you join the specified team", -1);
Console()->Register("top5", "?i", CFGFLAG_SERVER, ConTop5, this, "Shows the top 5 from the 1st, or starting at the specified number", -1);
#define CONSOLE_COMMAND(name, params, flags, callback, userdata, help, level) m_pConsole->Register(name, params, flags, callback, userdata, help, level);
#include "game/ddracecommands.h"
Console()->Chain("sv_motd", ConchainSpecialMotdupdate, this);

View file

@ -4,7 +4,7 @@
#include "entities/character.h"
#include "gamecontext.h"
#define NUM_TELEPORT 25
#define NUM_CHECKPOINTS 25
class CPlayerData
{
@ -18,20 +18,20 @@ public:
{
m_BestTime = 0;
m_CurrentTime = 0;
for(int i = 0; i < NUM_TELEPORT; i++)
for(int i = 0; i < NUM_CHECKPOINTS; i++)
m_aBestCpTime[i] = 0;
}
void Set(float Time, float CpTime[NUM_TELEPORT])
void Set(float Time, float CpTime[NUM_CHECKPOINTS])
{
m_BestTime = Time;
for(int i = 0; i < NUM_TELEPORT; i++)
for(int i = 0; i < NUM_CHECKPOINTS; i++)
m_aBestCpTime[i] = CpTime[i];
}
float m_BestTime;
float m_CurrentTime;
float m_aBestCpTime[NUM_TELEPORT];
float m_aBestCpTime[NUM_CHECKPOINTS];
};
class IScore

View file

@ -9,12 +9,11 @@
static LOCK gs_ScoreLock = 0;
CFileScore::CPlayerScore::CPlayerScore(const char *pName, float Score, const char *pIP, float aCpTime[NUM_TELEPORT])
CFileScore::CPlayerScore::CPlayerScore(const char *pName, float Score, float aCpTime[NUM_CHECKPOINTS])
{
str_copy(m_aName, pName, sizeof(m_aName));
m_Score = Score;
str_copy(m_aIP, pIP, sizeof(m_aIP));
for(int i = 0; i < NUM_TELEPORT; i++)
for(int i = 0; i < NUM_CHECKPOINTS; i++)
m_aCpTime[i] = aCpTime[i];
}
@ -57,10 +56,10 @@ void CFileScore::SaveScoreThread(void *pUser)
int t = 0;
for(sorted_array<CPlayerScore>::range r = pSelf->m_Top.all(); !r.empty(); r.pop_front())
{
f << r.front().m_aName << std::endl << r.front().m_Score << std::endl << r.front().m_aIP << std::endl;
f << r.front().m_aName << std::endl << r.front().m_Score << std::endl;
if(g_Config.m_SvCheckpointSave)
{
for(int c = 0; c < NUM_TELEPORT; c++)
for(int c = 0; c < NUM_CHECKPOINTS; c++)
f << r.front().m_aCpTime[c] << " ";
f << std::endl;
}
@ -94,26 +93,25 @@ void CFileScore::Init()
while(!f.eof() && !f.fail())
{
std::string TmpName, TmpScore, TmpIP, TmpCpLine;
std::string TmpName, TmpScore, TmpCpLine;
std::getline(f, TmpName);
if(!f.eof() && TmpName != "")
{
std::getline(f, TmpScore);
std::getline(f, TmpIP);
float aTmpCpTime[NUM_TELEPORT] = {0};
float aTmpCpTime[NUM_CHECKPOINTS] = {0};
if(g_Config.m_SvCheckpointSave)
{
std::getline(f, TmpCpLine);
char *pTime = strtok((char*)TmpCpLine.c_str(), " ");
int i = 0;
while(pTime != NULL && i < NUM_TELEPORT)
while(pTime != NULL && i < NUM_CHECKPOINTS)
{
aTmpCpTime[i] = atof(pTime);
pTime = strtok(NULL, " ");
i++;
}
}
m_Top.add(*new CPlayerScore(TmpName.c_str(), atof(TmpScore.c_str()), TmpIP.c_str(), aTmpCpTime));
m_Top.add(*new CPlayerScore(TmpName.c_str(), atof(TmpScore.c_str()), aTmpCpTime));
}
}
f.close();
@ -124,26 +122,6 @@ void CFileScore::Init()
((CGameControllerDDRace*)GameServer()->m_pController)->m_CurrentRecord = m_Top[0].m_Score;
}
CFileScore::CPlayerScore *CFileScore::SearchScore(int ID, bool ScoreIP, int *pPosition)
{
char aIP[16];
Server()->GetClientIP(ID, aIP, sizeof(aIP));
int Pos = 1;
for(sorted_array<CPlayerScore>::range r = m_Top.all(); !r.empty(); r.pop_front())
{
if(!strcmp(r.front().m_aIP, aIP) && g_Config.m_SvScoreIP && ScoreIP)
{
if(pPosition)
*pPosition = Pos;
return &r.front();
}
Pos++;
}
return SearchName(Server()->ClientName(ID), pPosition, 0);
}
CFileScore::CPlayerScore *CFileScore::SearchName(const char *pName, int *pPosition, bool NoCase)
{
CPlayerScore *pPlayer = 0;
@ -174,18 +152,16 @@ CFileScore::CPlayerScore *CFileScore::SearchName(const char *pName, int *pPositi
return pPlayer;
}
void CFileScore::UpdatePlayer(int ID, float Score, float aCpTime[NUM_TELEPORT])
void CFileScore::UpdatePlayer(int ID, float Score, float aCpTime[NUM_CHECKPOINTS])
{
const char *pName = Server()->ClientName(ID);
char aIP[16];
Server()->GetClientIP(ID, aIP, sizeof(aIP));
lock_wait(gs_ScoreLock);
CPlayerScore *pPlayer = SearchScore(ID, 1, 0);
CPlayerScore *pPlayer = SearchScore(ID, 0);
if(pPlayer)
{
for(int c = 0; c < NUM_TELEPORT; c++)
for(int c = 0; c < NUM_CHECKPOINTS; c++)
pPlayer->m_aCpTime[c] = aCpTime[c];
pPlayer->m_Score = Score;
@ -194,7 +170,7 @@ void CFileScore::UpdatePlayer(int ID, float Score, float aCpTime[NUM_TELEPORT])
sort(m_Top.all());
}
else
m_Top.add(*new CPlayerScore(pName, Score, aIP, aCpTime));
m_Top.add(*new CPlayerScore(pName, Score, aCpTime));
lock_release(gs_ScoreLock);
Save();
@ -202,13 +178,10 @@ void CFileScore::UpdatePlayer(int ID, float Score, float aCpTime[NUM_TELEPORT])
void CFileScore::LoadScore(int ClientID)
{
char aIP[16];
Server()->GetClientIP(ClientID, aIP, sizeof(aIP));
CPlayerScore *pPlayer = SearchScore(ClientID, 0, 0);
if(pPlayer && strcmp(pPlayer->m_aIP, aIP) != 0)
CPlayerScore *pPlayer = SearchScore(ClientID, 0);
if(pPlayer)
{
lock_wait(gs_ScoreLock);
str_copy(pPlayer->m_aIP, aIP, sizeof(pPlayer->m_aIP));
lock_release(gs_ScoreLock);
Save();
}
@ -246,7 +219,7 @@ void CFileScore::ShowRank(int ClientID, const char* pName, bool Search)
char aBuf[512];
if(!Search)
pScore = SearchScore(ClientID, 1, &Pos);
pScore = SearchScore(ClientID, &Pos);
else
pScore = SearchName(pName, &Pos, 1);

View file

@ -17,11 +17,10 @@ class CFileScore : public IScore
public:
char m_aName[MAX_NAME_LENGTH];
float m_Score;
char m_aIP[16];
float m_aCpTime[NUM_TELEPORT];
float m_aCpTime[NUM_CHECKPOINTS];
CPlayerScore() {};
CPlayerScore(const char *pName, float Score, const char *pIP, float aCpTime[NUM_TELEPORT]);
CPlayerScore(const char *pName, float Score, float aCpTime[NUM_CHECKPOINTS]);
bool operator<(const CPlayerScore& other) { return (this->m_Score < other.m_Score); }
};
@ -31,9 +30,10 @@ class CFileScore : public IScore
CGameContext *GameServer() { return m_pGameServer; }
IServer *Server() { return m_pServer; }
CPlayerScore *SearchScore(int ID, bool ScoreIP, int *pPosition);
CPlayerScore *SearchScore(int ID, int *pPosition){ return SearchName(Server()->ClientName(ID), pPosition, 0 );};
;
CPlayerScore *SearchName(const char *pName, int *pPosition, bool MatchCase);
void UpdatePlayer(int ID, float Score, float aCpTime[NUM_TELEPORT]);
void UpdatePlayer(int ID, float Score, float aCpTime[NUM_CHECKPOINTS]);
void Init();
void Save();

View file

@ -87,7 +87,7 @@ void CSqlScore::Init()
{
// create tables
char aBuf[768];
str_format(aBuf, sizeof(aBuf), "CREATE TABLE IF NOT EXISTS %s_%s_race (Name VARCHAR(31) NOT NULL, Time FLOAT DEFAULT 0, IP VARCHAR(16) DEFAULT '0.0.0.0', cp1 FLOAT DEFAULT 0, cp2 FLOAT DEFAULT 0, cp3 FLOAT DEFAULT 0, cp4 FLOAT DEFAULT 0, cp5 FLOAT DEFAULT 0, cp6 FLOAT DEFAULT 0, cp7 FLOAT DEFAULT 0, cp8 FLOAT DEFAULT 0, cp9 FLOAT DEFAULT 0, cp10 FLOAT DEFAULT 0, cp11 FLOAT DEFAULT 0, cp12 FLOAT DEFAULT 0, cp13 FLOAT DEFAULT 0, cp14 FLOAT DEFAULT 0, cp15 FLOAT DEFAULT 0, cp16 FLOAT DEFAULT 0, cp17 FLOAT DEFAULT 0, cp18 FLOAT DEFAULT 0, cp19 FLOAT DEFAULT 0, cp20 FLOAT DEFAULT 0, cp21 FLOAT DEFAULT 0, cp22 FLOAT DEFAULT 0, cp23 FLOAT DEFAULT 0, cp24 FLOAT DEFAULT 0, cp25 FLOAT DEFAULT 0);", m_pPrefix, m_aMap);
str_format(aBuf, sizeof(aBuf), "CREATE TABLE IF NOT EXISTS %s_%s_race (Name VARCHAR(31) NOT NULL, Time FLOAT DEFAULT 0, cp1 FLOAT DEFAULT 0, cp2 FLOAT DEFAULT 0, cp3 FLOAT DEFAULT 0, cp4 FLOAT DEFAULT 0, cp5 FLOAT DEFAULT 0, cp6 FLOAT DEFAULT 0, cp7 FLOAT DEFAULT 0, cp8 FLOAT DEFAULT 0, cp9 FLOAT DEFAULT 0, cp10 FLOAT DEFAULT 0, cp11 FLOAT DEFAULT 0, cp12 FLOAT DEFAULT 0, cp13 FLOAT DEFAULT 0, cp14 FLOAT DEFAULT 0, cp15 FLOAT DEFAULT 0, cp16 FLOAT DEFAULT 0, cp17 FLOAT DEFAULT 0, cp18 FLOAT DEFAULT 0, cp19 FLOAT DEFAULT 0, cp20 FLOAT DEFAULT 0, cp21 FLOAT DEFAULT 0, cp22 FLOAT DEFAULT 0, cp23 FLOAT DEFAULT 0, cp24 FLOAT DEFAULT 0, cp25 FLOAT DEFAULT 0);", m_pPrefix, m_aMap);
m_pStatement->execute(aBuf);
dbg_msg("SQL", "Tables were created successfully");
@ -134,60 +134,18 @@ void CSqlScore::LoadScoreThread(void *pUser)
pData->m_pSqlData->ClearString(pData->m_aName);
char aBuf[512];
// check if there is an entry with the same ip
if(g_Config.m_SvScoreIP)
{
str_format(aBuf, sizeof(aBuf), "SELECT * FROM %s_%s_race WHERE IP='%s';", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap, pData->m_aIP);
pData->m_pSqlData->m_pResults = pData->m_pSqlData->m_pStatement->executeQuery(aBuf);
if(pData->m_pSqlData->m_pResults->next())
{
// get the best time
pData->m_pSqlData->PlayerData(pData->m_ClientID)->m_BestTime = (float)pData->m_pSqlData->m_pResults->getDouble("Time");
char aColumn[8];
for(int i = 0; i < NUM_TELEPORT; i++)
{
str_format(aColumn, sizeof(aColumn), "cp%d", i+1);
pData->m_pSqlData->PlayerData(pData->m_ClientID)->m_aBestCpTime[i] = (float)pData->m_pSqlData->m_pResults->getDouble(aColumn);
}
dbg_msg("SQL", "Getting best time done");
// delete statement and results
delete pData->m_pSqlData->m_pStatement;
delete pData->m_pSqlData->m_pResults;
// disconnect from database
pData->m_pSqlData->Disconnect();
delete pData;
lock_release(gs_SqlLock);
return;
}
}
str_format(aBuf, sizeof(aBuf), "SELECT * FROM %s_%s_race WHERE Name='%s';", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap, pData->m_aName);
pData->m_pSqlData->m_pResults = pData->m_pSqlData->m_pStatement->executeQuery(aBuf);
if(pData->m_pSqlData->m_pResults->next())
{
// check if IP differs
const char* pIP = pData->m_pSqlData->m_pResults->getString("IP").c_str();
if(str_comp(pIP, pData->m_aIP) != 0)
{
// set the new ip
str_format(aBuf, sizeof(aBuf), "UPDATE %s_%s_race SET IP='%s' WHERE Name='%s';", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap, pData->m_aIP, pData->m_aName);
pData->m_pSqlData->m_pStatement->execute(aBuf);
}
// get the best time
pData->m_pSqlData->PlayerData(pData->m_ClientID)->m_BestTime = (float)pData->m_pSqlData->m_pResults->getDouble("Time");
char aColumn[8];
if(g_Config.m_SvCheckpointSave)
{
for(int i = 0; i < NUM_TELEPORT; i++)
for(int i = 0; i < NUM_CHECKPOINTS; i++)
{
str_format(aColumn, sizeof(aColumn), "cp%d", i+1);
pData->m_pSqlData->PlayerData(pData->m_ClientID)->m_aBestCpTime[i] = (float)pData->m_pSqlData->m_pResults->getDouble(aColumn);
@ -220,7 +178,6 @@ void CSqlScore::LoadScore(int ClientID)
CSqlScoreData *Tmp = new CSqlScoreData();
Tmp->m_ClientID = ClientID;
str_copy(Tmp->m_aName, Server()->ClientName(ClientID), sizeof(Tmp->m_aName));
Server()->GetClientIP(ClientID, Tmp->m_aIP, sizeof(Tmp->m_aIP));
Tmp->m_pSqlData = this;
void *LoadThread = thread_create(LoadScoreThread, Tmp);
@ -245,21 +202,21 @@ void CSqlScore::SaveScoreThread(void *pUser)
char aBuf[768];
// fisrt check for IP
str_format(aBuf, sizeof(aBuf), "SELECT * FROM %s_%s_race WHERE IP='%s';", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap, pData->m_aIP);
// fisrt check for the name
str_format(aBuf, sizeof(aBuf), "SELECT * FROM %s_%s_race WHERE Name='%s';", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap, pData->m_aName);
pData->m_pSqlData->m_pResults = pData->m_pSqlData->m_pStatement->executeQuery(aBuf);
// if ip found...
// if the name is found...
if(pData->m_pSqlData->m_pResults->next())
{
// update time
if(g_Config.m_SvCheckpointSave)
str_format(aBuf, sizeof(aBuf), "UPDATE %s_%s_race SET Name='%s', Time='%.2f', cp1='%.2f', cp2='%.2f', cp3='%.2f', cp4='%.2f', cp5='%.2f', cp6='%.2f', cp7='%.2f', cp8='%.2f', cp9='%.2f', cp10='%.2f', cp11='%.2f', cp12='%.2f', cp13='%.2f', cp14='%.2f', cp15='%.2f', cp16='%.2f', cp17='%.2f', cp18='%.2f', cp19='%.2f', cp20='%.2f', cp21='%.2f', cp22='%.2f', cp23='%.2f', cp24='%.2f', cp25='%.2f' WHERE IP='%s';", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap, pData->m_aName, pData->m_Time, pData->m_aCpCurrent[0], pData->m_aCpCurrent[1], pData->m_aCpCurrent[2], pData->m_aCpCurrent[3], pData->m_aCpCurrent[4], pData->m_aCpCurrent[5], pData->m_aCpCurrent[6], pData->m_aCpCurrent[7], pData->m_aCpCurrent[8], pData->m_aCpCurrent[9], pData->m_aCpCurrent[10], pData->m_aCpCurrent[11], pData->m_aCpCurrent[12], pData->m_aCpCurrent[13], pData->m_aCpCurrent[14], pData->m_aCpCurrent[15], pData->m_aCpCurrent[16], pData->m_aCpCurrent[17], pData->m_aCpCurrent[18], pData->m_aCpCurrent[19], pData->m_aCpCurrent[20], pData->m_aCpCurrent[21], pData->m_aCpCurrent[22], pData->m_aCpCurrent[23], pData->m_aCpCurrent[24], pData->m_aIP);
str_format(aBuf, sizeof(aBuf), "UPDATE %s_%s_race SET Time='%.2f', cp1='%.2f', cp2='%.2f', cp3='%.2f', cp4='%.2f', cp5='%.2f', cp6='%.2f', cp7='%.2f', cp8='%.2f', cp9='%.2f', cp10='%.2f', cp11='%.2f', cp12='%.2f', cp13='%.2f', cp14='%.2f', cp15='%.2f', cp16='%.2f', cp17='%.2f', cp18='%.2f', cp19='%.2f', cp20='%.2f', cp21='%.2f', cp22='%.2f', cp23='%.2f', cp24='%.2f', cp25='%.2f' WHERE Name='%s';", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap, pData->m_Time, pData->m_aCpCurrent[0], pData->m_aCpCurrent[1], pData->m_aCpCurrent[2], pData->m_aCpCurrent[3], pData->m_aCpCurrent[4], pData->m_aCpCurrent[5], pData->m_aCpCurrent[6], pData->m_aCpCurrent[7], pData->m_aCpCurrent[8], pData->m_aCpCurrent[9], pData->m_aCpCurrent[10], pData->m_aCpCurrent[11], pData->m_aCpCurrent[12], pData->m_aCpCurrent[13], pData->m_aCpCurrent[14], pData->m_aCpCurrent[15], pData->m_aCpCurrent[16], pData->m_aCpCurrent[17], pData->m_aCpCurrent[18], pData->m_aCpCurrent[19], pData->m_aCpCurrent[20], pData->m_aCpCurrent[21], pData->m_aCpCurrent[22], pData->m_aCpCurrent[23], pData->m_aCpCurrent[24], pData->m_aName);
else
str_format(aBuf, sizeof(aBuf), "UPDATE %s_%s_race SET Name='%s', Time='%.2f' WHERE IP='%s';", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap, pData->m_aName, pData->m_Time, pData->m_aIP);
str_format(aBuf, sizeof(aBuf), "UPDATE %s_%s_race SET Time='%.2f' WHERE Name='%s';", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap, pData->m_Time, pData->m_aName);
pData->m_pSqlData->m_pStatement->execute(aBuf);
dbg_msg("SQL", "Updateing time done");
dbg_msg("SQL", "Updating time done");
// delete results statement
delete pData->m_pSqlData->m_pResults;
@ -276,10 +233,10 @@ void CSqlScore::SaveScoreThread(void *pUser)
}
// if no entry found... create a new one
str_format(aBuf, sizeof(aBuf), "INSERT IGNORE INTO %s_%s_race(Name, IP, Time, cp1, cp2, cp3, cp4, cp5, cp6, cp7, cp8, cp9, cp10, cp11, cp12, cp13, cp14, cp15, cp16, cp17, cp18, cp19, cp20, cp21, cp22, cp23, cp24, cp25) VALUES ('%s', '%s', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f');", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap, pData->m_aName, pData->m_aIP, pData->m_Time, pData->m_aCpCurrent[0], pData->m_aCpCurrent[1], pData->m_aCpCurrent[2], pData->m_aCpCurrent[3], pData->m_aCpCurrent[4], pData->m_aCpCurrent[5], pData->m_aCpCurrent[6], pData->m_aCpCurrent[7], pData->m_aCpCurrent[8], pData->m_aCpCurrent[9], pData->m_aCpCurrent[10], pData->m_aCpCurrent[11], pData->m_aCpCurrent[12], pData->m_aCpCurrent[13], pData->m_aCpCurrent[14], pData->m_aCpCurrent[15], pData->m_aCpCurrent[16], pData->m_aCpCurrent[17], pData->m_aCpCurrent[18], pData->m_aCpCurrent[19], pData->m_aCpCurrent[20], pData->m_aCpCurrent[21], pData->m_aCpCurrent[22], pData->m_aCpCurrent[23], pData->m_aCpCurrent[24]);
str_format(aBuf, sizeof(aBuf), "INSERT IGNORE INTO %s_%s_race(Name, Time, cp1, cp2, cp3, cp4, cp5, cp6, cp7, cp8, cp9, cp10, cp11, cp12, cp13, cp14, cp15, cp16, cp17, cp18, cp19, cp20, cp21, cp22, cp23, cp24, cp25) VALUES ('%s', '%s', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f');", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap, pData->m_aName, pData->m_Time, pData->m_aCpCurrent[0], pData->m_aCpCurrent[1], pData->m_aCpCurrent[2], pData->m_aCpCurrent[3], pData->m_aCpCurrent[4], pData->m_aCpCurrent[5], pData->m_aCpCurrent[6], pData->m_aCpCurrent[7], pData->m_aCpCurrent[8], pData->m_aCpCurrent[9], pData->m_aCpCurrent[10], pData->m_aCpCurrent[11], pData->m_aCpCurrent[12], pData->m_aCpCurrent[13], pData->m_aCpCurrent[14], pData->m_aCpCurrent[15], pData->m_aCpCurrent[16], pData->m_aCpCurrent[17], pData->m_aCpCurrent[18], pData->m_aCpCurrent[19], pData->m_aCpCurrent[20], pData->m_aCpCurrent[21], pData->m_aCpCurrent[22], pData->m_aCpCurrent[23], pData->m_aCpCurrent[24]);
pData->m_pSqlData->m_pStatement->execute(aBuf);
dbg_msg("SQL", "Updateing time done");
dbg_msg("SQL", "Updating time done");
// delete results statement
delete pData->m_pSqlData->m_pResults;
@ -291,7 +248,7 @@ void CSqlScore::SaveScoreThread(void *pUser)
}
// disconnect from database
pData->m_pSqlData->Disconnect();
pData->m_pSqlData->Disconnect(); //TODO:Check if an exception is caught will this still execute ?
}
delete pData;
@ -304,9 +261,8 @@ void CSqlScore::SaveScore(int ClientID, float Time, CCharacter *pChar)
CSqlScoreData *Tmp = new CSqlScoreData();
Tmp->m_ClientID = ClientID;
str_copy(Tmp->m_aName, Server()->ClientName(ClientID), sizeof(Tmp->m_aName));
Server()->GetClientIP(ClientID, Tmp->m_aIP, sizeof(Tmp->m_aIP));
Tmp->m_Time = Time;
for(int i = 0; i < NUM_TELEPORT; i++)
for(int i = 0; i < NUM_CHECKPOINTS; i++)
Tmp->m_aCpCurrent[i] = pChar->m_CpCurrent[i];
Tmp->m_pSqlData = this;
@ -332,7 +288,7 @@ void CSqlScore::ShowRankThread(void *pUser)
// check sort methode
char aBuf[512];
str_format(aBuf, sizeof(aBuf), "SELECT Name, IP, Time FROM %s_%s_race ORDER BY `Time` ASC;", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap);
str_format(aBuf, sizeof(aBuf), "SELECT Name, Time FROM %s_%s_race ORDER BY `Time` ASC;", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap);
pData->m_pSqlData->m_pResults = pData->m_pSqlData->m_pStatement->executeQuery(aBuf);
int RowCount = 0;
bool Found = false;
@ -348,11 +304,6 @@ void CSqlScore::ShowRankThread(void *pUser)
break;
}
}
else if(!str_comp(pData->m_pSqlData->m_pResults->getString("IP").c_str(), pData->m_aIP))
{
Found = true;
break;
}
}
if(!Found)
@ -386,7 +337,7 @@ void CSqlScore::ShowRankThread(void *pUser)
}
// disconnect from database
pData->m_pSqlData->Disconnect();
pData->m_pSqlData->Disconnect();//TODO:Check if an exception is caught will this still execute ?
}
delete pData;
@ -399,7 +350,6 @@ void CSqlScore::ShowRank(int ClientID, const char* pName, bool Search)
CSqlScoreData *Tmp = new CSqlScoreData();
Tmp->m_ClientID = ClientID;
str_copy(Tmp->m_aName, pName, sizeof(Tmp->m_aName));
Server()->GetClientIP(ClientID, Tmp->m_aIP, sizeof(Tmp->m_aIP));
Tmp->m_Search = Search;
str_format(Tmp->m_aRequestingPlayer, sizeof(Tmp->m_aRequestingPlayer), " (%s)", Server()->ClientName(ClientID));
Tmp->m_pSqlData = this;

View file

@ -64,9 +64,8 @@ struct CSqlScoreData
CSqlScore *m_pSqlData;
int m_ClientID;
char m_aName[16];
char m_aIP[16];
float m_Time;
float m_aCpCurrent[NUM_TELEPORT];
float m_aCpCurrent[NUM_CHECKPOINTS];
int m_Num;
bool m_Search;
char m_aRequestingPlayer[MAX_NAME_LENGTH];