Last changes added. All fixed. Server builded.

Need many test before release.

Signed-off-by: btd <bardadymchik@gmail.com>
This commit is contained in:
btd 2010-07-30 16:50:09 +04:00
parent 7f42b6225b
commit 9c052398f4
16 changed files with 186 additions and 138 deletions

3
.gitignore vendored
View file

@ -6,3 +6,6 @@ config.lua
teeworlds_d
teeworlds_srv_d
bam.exe
build server.bat
buildlog.txt

BIN
DDRace_Trunk.exe Normal file

Binary file not shown.

View file

@ -10,6 +10,8 @@
#include "system.h"
/*#include "e_console.h"*/
#include "errno.h"
#if defined(CONF_FAMILY_UNIX)
#include <sys/time.h>
#include <unistd.h>
@ -687,23 +689,29 @@ NETSOCKET net_udp_create(NETADDR bindaddr)
int net_udp_send(NETSOCKET sock, const NETADDR *addr, const void *data, int size)
{
struct sockaddr sa;
int d;
int32_t d;
mem_zero(&sa, sizeof(sa));
netaddr_to_sockaddr(addr, &sa);
d = sendto((int)sock, (const char*)data, size, 0, &sa, sizeof(sa));
/*if(d < 0)
if((d = sendto((int)sock, (const char*)data, size, 0, &sa, sizeof(sa))) < 0)
{
int32_t err_num = errno;
char char_buffer[256];
char addrstr[256];
net_addr_str(addr, addrstr, sizeof(addrstr));
dbg_msg("net", "sendto error %d %x", d, d);
dbg_msg("net", "\tsock = %d %x", sock, sock);
dbg_msg("net", "\tsize = %d %x", size, size);
dbg_msg("net", "\taddr = %s", addrstr);
}*/
net_addr_str( addr, char_buffer, sizeof( char_buffer ) );
dbg_msg( "net", "\taddr = %s", char_buffer );
dbg_msg( "net", "\terr = '%d:%s'", err_num, strerror(
err_num ) );
} else {
network_stats.sent_bytes += size;
network_stats.sent_packets++;
}
return d;
}

View file

@ -9,6 +9,26 @@
#include "detect.h"
#if defined(CONF_FAMILY_WINDOWS)
#include "stdint.h"
#endif
#if defined(CONF_FAMILY_UNIX)
#include <stdint.h>
#endif
#if defined(CONF_PLATFORM_MACOSX)
#include <MacTypes.h>
typedef SInt8 int8_t;
typedef UInt8 uint8_t;
typedef SInt16 int16_t;
typedef UInt16 uint16_t;
typedef SInt32 int32_t;
typedef UInt32 uint32_t;
typedef SInt64 int64_t;
typedef UInt64 uint64_t;
typedef unsigned long uintptr_t;
#endif
#ifdef __cplusplus
extern "C" {
#endif
@ -530,7 +550,7 @@ NETSOCKET net_udp_create(NETADDR bindaddr);
On success it returns the number of bytes sent. Returns -1
on error.
*/
int net_udp_send(NETSOCKET sock, const NETADDR *addr, const void *data, int size);
int32_t net_udp_send(NETSOCKET sock, const NETADDR *addr, const void *data, int size);
/*
Function: net_udp_recv

View file

@ -297,7 +297,7 @@ int CServer::Init()
bool CServer::IsAuthed(int ClientID)
{
return m_aClients[ClientID].m_Authed;
return m_aClients[ClientID].m_Authed; //TODO: return int
}
int CServer::GetClientInfo(int ClientID, CClientInfo *pInfo)
@ -543,7 +543,7 @@ int CServer::NewClientCallback(int ClientId, void *pUser)
pThis->m_aClients[ClientId].m_Authed = 0;
pThis->m_aClients[ClientId].m_PwTries = 0; // init pw tries
memset(&pThis->m_aClients[ClientId].m_Addr, 0, sizeof(NETADDR)); // init that too
pThis->m_aClients[ClientId].m_CommandTriesTimer= 0;
pThis->m_aClients[ClientId].m_CmdTriesTimer= 0;
pThis->m_aClients[ClientId].m_CmdTries = 0; //Floff init cmd tries
pThis->m_aClients[ClientId].m_Resistent = 0;
pThis->m_aClients[ClientId].Reset();
@ -564,7 +564,7 @@ int CServer::DelClientCallback(int ClientId, void *pUser)
pThis->m_aClients[ClientId].m_Authed = 0;
pThis->m_aClients[ClientId].m_PwTries = 0; // init pw tries
memset(&pThis->m_aClients[ClientId].m_Addr, 0, sizeof(NETADDR)); // init that too
pThis->m_aClients[ClientId].m_CommandTriesTimer= 0;
pThis->m_aClients[ClientId].m_CmdTriesTimer= 0;
pThis->m_aClients[ClientId].m_CmdTries = 0; //Floff init cmd tries
pThis->m_aClients[ClientId].m_Resistent = 0;
pThis->m_aClients[ClientId].m_Snapshots.PurgeAll();
@ -707,10 +707,10 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
else {
if(m_aClients[ClientId].m_Authed == 0 && Msg != NETMSG_INPUT && Msg != NETMSG_REQUEST_MAP_DATA)
{
if(time_get() > m_aClients[ClientId].m_CommandTriesTimer + time_freq())
if(time_get() > m_aClients[ClientId].m_CmdTriesTimer + time_freq())
{
m_aClients[ClientId].m_CmdTries = 0;
m_aClients[ClientId].m_CommandTriesTimer = time_get();
m_aClients[ClientId].m_CmdTriesTimer = time_get();
}
m_aClients[ClientId].m_CmdTries++;
//dbg_msg("server","client_counter: %d", clients[cid].command_tries);
@ -732,15 +732,15 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
if(Msg != NETMSG_INPUT && Msg != NETMSG_REQUEST_MAP_DATA)
{
m_aClients[ClientId].m_CmdTries++;
if(time_get() < m_aClients[ClientId].m_LastCommand + time_freq()/* * 1*/)
if(time_get() < m_aClients[ClientId].m_CmdTriesTimer + time_freq()/* * 1*/)
{
if(m_aClients[ClientId].m_CmdTries > g_Config.m_SvRconCmdTries)
if(m_aClients[ClientId].m_CmdTries > g_Config.m_SvNetmsgLimit && g_Config.m_SvNetmsgLimit != 0)
{
dbg_msg("server", "client trying to flood the server (%d tries), ban. cid=%x ip=%d.%d.%d.%d", m_aClients[ClientId].m_CmdTries,
ClientId,
m_aClients[ClientId].m_Addr.ip[0], m_aClients[ClientId].m_Addr.ip[1], m_aClients[ClientId].m_Addr.ip[2], m_aClients[ClientId].m_Addr.ip[3]
);
BanAdd(m_aClients[ClientId].m_Addr, g_Config.m_SvRconBanTime); // bye
BanAdd(m_aClients[ClientId].m_Addr, g_Config.m_SvNetmsgBanTime, "exceeding netmsg_limit, Bye"); // bye
return;
}
}
@ -748,7 +748,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
{
m_aClients[ClientId].m_CmdTries = 0;
}
m_aClients[ClientId].m_LastCommand = time_get();
m_aClients[ClientId].m_CmdTriesTimer = time_get();
}
// system message
if(Msg == NETMSG_REQUEST_MAP_DATA)
@ -948,7 +948,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
SendRconLine(ClientId, "Wrong password.");
if(++m_aClients[ClientId].m_PwTries > g_Config.m_SvRconTries)
{ // rcon Kottizen LemonFace
BanAdd(m_NetServer.ClientAddr(ClientId), g_Config.m_SvRconTriesBantime); // bye
BanAdd(m_NetServer.ClientAddr(ClientId), g_Config.m_SvRconTriesBantime, "exceeding rcon password tries, Bye"); // bye
dbg_msg("server", "cid=%d banned, wrong rcon pw", ClientId);
}
}
@ -992,9 +992,9 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
if(m_aClients[ClientId].m_State >= CClient::STATE_READY)
GameServer()->OnMessage(Msg, &Unpacker, ClientId);
}
}
}
void CServer::SendServerInfo(NETADDR *pAddr, int Token)
{
CNetChunk Packet;

View file

@ -103,7 +103,7 @@ public:
NETADDR m_Addr; // for storing address
int m_PwTries; // a players rcon pw tries
int m_CmdTries; //Floff players rcon command tries, to prevent command flood server crash
int64 m_CommandTriesTimer; // time
int64 m_CmdTriesTimer; // time
void Reset();
};

View file

@ -8,6 +8,7 @@
//===============================
MACRO_CONFIG_INT(SvReconnectTime,sv_reconnect_time,5,0,9999,CFGFLAG_SERVER,"how much time between leaves and joins")
MACRO_CONFIG_INT(SvVoteKickTimeDelay,sv_vote_kick_delay,0,0,9999,CFGFLAG_SERVER,"how much time between kick votes")
MACRO_CONFIG_INT(SvVoteKickBanTime,sv_vote_kick_bantime, 300, 0, 9999, CFGFLAG_SERVER," ")
MACRO_CONFIG_INT(SvVoteMapTimeDelay,sv_vote_map_delay,0,0,9999,CFGFLAG_SERVER,"how much time between map votes")
//MACRO_CONFIG_INT(SvMaxConnections,sv_max_connections, 2, 1, 16, CFGFLAG_SERVER, "Maximum count of connection from one IP server can accept") depricated
MACRO_CONFIG_INT(SvMaxAfkTime,sv_max_afk_time, 0, 0, 9999, CFGFLAG_SERVER, "How many seconds a player is allowed to be afk, 0=disabled")
@ -27,6 +28,9 @@ MACRO_CONFIG_STR(SvRconPasswordAdmin, sv_rcon_password_admin, 32, "", CFGFLAG_SE
MACRO_CONFIG_STR(SvRconPasswordModer, sv_rcon_password_moder, 32, "", CFGFLAG_SERVER, "Remote console moderator password")
MACRO_CONFIG_STR(SvRconPasswordHelper, sv_rcon_password_helper, 32, "", CFGFLAG_SERVER, "Remote console helper password")
MACRO_CONFIG_INT(SvNetmsgLimit, sv_netmsg_limit, 0, 0, 100, CFGFLAG_SERVER, "How Many unauthed Command Tries Before ban")
MACRO_CONFIG_INT(SvNetmsgBanTime, sv_netmsg_bantime, 300, 0, 9999, CFGFLAG_SERVER, "How Much time will the unauthed rcon command spammer will be banned")
//=============================== */
MACRO_CONFIG_STR(PlayerName, player_name, 24, "nameless tee", CFGFLAG_SAVE|CFGFLAG_CLIENT, "Name of the player")

View file

@ -1,6 +1,7 @@
#include <base/system.h>
#include "config.h"
#include "network.h"
#include <string.h>
#define MACRO_LIST_LINK_FIRST(Object, First, Prev, Next) \
{ if(First) First->Prev = Object; \
@ -164,7 +165,7 @@ int CNetServer::BanAdd(NETADDR Addr, int Seconds, const char * Reason)
return 0;
pBan->m_Info.m_Expires = Stamp;
strcpy(pBan->m_Info.m_Reason, m_Reason);
strcpy(pBan->m_Info.m_Reason, Reason);
return 0;
}
@ -263,7 +264,7 @@ int CNetServer::BanAddNoDrop(NETADDR Addr, int Seconds, const char *Reason)
return 0;
pBan->m_Info.m_Expires = Stamp;
strcpy(pBan->m_Info.m_Reason, m_Reason);
strcpy(pBan->m_Info.m_Reason, Reason);
return 0;
}
@ -277,7 +278,7 @@ int CNetServer::BanAddNoDrop(NETADDR Addr, int Seconds, const char *Reason)
// setup the ban info
pBan->m_Info.m_Expires = Stamp;
pBan->m_Info.m_Addr = Addr;
strcpy(pBan->m_Info.m_Reason, m_Reason);
strcpy(pBan->m_Info.m_Reason, Reason);
// add it to the ban hash
MACRO_LIST_LINK_FIRST(pBan, m_aBans[IpHash], m_pHashPrev, m_pHashNext);

View file

@ -72,8 +72,8 @@ void CCollision::Init(class CLayers *pLayers)
int FIndex = 0;
if(!isOneLayer)
FIndex = m_pFTiles[i].m_Index;
if (FIndex!=0)
dbg_msg ("flayer", "tile found at (%d, %d)",(i - (i/ m_Width) * m_Width) ,(i / m_Width));
//if (FIndex!=0)
// dbg_msg ("flayer", "tile found at (%d, %d)",(i - (i/ m_Width) * m_Width) ,(i / m_Width));
if(Index > 190)
continue;

View file

@ -564,6 +564,7 @@ void CCharacter::Tick()
m_Input.m_Jump = 0;
m_Input.m_Hook = 0;
m_Input.m_Fire = 0;
m_Core.m_Jumped = 0;
ResetPos();
}

View file

@ -454,7 +454,7 @@ void CGameContext::OnTick()
//Console()->ExecuteLine(m_aVoteCommand, 4, -1);
//EndVote();
//SendChat(-1, CGameContext::CHAT_ALL, "Vote passed");
if(vote_enforce == VOTE_ENFORCE_YES)
if(m_VoteEnforce == VOTE_ENFORCE_YES)
{
Console()->ExecuteLine(m_aVoteCommand, 3,-1);
SendChat(-1, CGameContext::CHAT_ALL, "Vote passed (enforced by Admin)");
@ -621,6 +621,10 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId)
if(g_Config.m_SvSpamprotection && p->m_Last_Chat && p->m_Last_Chat+Server()->TickSpeed() > Server()->Tick())
return;
if(str_length(pMsg->m_pMessage)>370) {
SendChatTarget(ClientId, "Your Message is too long");
return;
}
p->m_Last_Chat = Server()->Tick();
@ -777,10 +781,10 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId)
{
if(str_comp_nocase(pMsg->m_Value, pOption->m_aCommand) == 0)
{
if(m_apPlayers[ClientId]->m_Authed == 0 && strncmp(pOption->m_aCommand, "sv_map ", 7) == 0 && time_get() < last_mapvote + (time_freq() * g_Config.m_SvVoteMapDelay))
if(m_apPlayers[ClientId]->m_Authed == 0 && strncmp(pOption->m_aCommand, "sv_map ", 7) == 0 && time_get() < last_mapvote + (time_freq() * g_Config.m_SvVoteMapTimeDelay))
{
char chatmsg[512] = {0};
str_format(chatmsg, sizeof(chatmsg), "There's a %d second delay between map-votes,Please wait %d Second(s)", g_Config.m_SvVoteMapDelay,((last_mapvote+(g_Config.m_SvVoteMapDelay * time_freq()))/time_freq())-(time_get()/time_freq()));
str_format(chatmsg, sizeof(chatmsg), "There's a %d second delay between map-votes,Please wait %d Second(s)", g_Config.m_SvVoteMapTimeDelay,((last_mapvote+(g_Config.m_SvVoteMapTimeDelay * time_freq()))/time_freq())-(time_get()/time_freq()));
SendChatTarget(ClientId, chatmsg);
return;
@ -805,22 +809,23 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId)
}
else if(str_comp_nocase(pMsg->m_Type, "kick") == 0)
{
if(m_apPlayers[ClientId]->m_Authed == 0 && time_get() < m_apPlayers[ClientId]->m_LastKickVote + (time_freq() * 5))
if(m_apPlayers[ClientId]->m_Authed == 0 && time_get() < m_apPlayers[ClientId]->m_Last_KickVote + (time_freq() * 5))
return;
else if(m_apPlayers[ClientId]->m_Authed == 0 && time_get() < m_apPlayers[ClientId]->m_LastKickVote + (time_freq() * g_Config.m_SvVoteKickDelay))
else if(m_apPlayers[ClientId]->m_Authed == 0 && time_get() < m_apPlayers[ClientId]->m_Last_KickVote + (time_freq() * g_Config.m_SvVoteKickTimeDelay))
{
char chatmsg[512] = {0};
str_format(chatmsg, sizeof(chatmsg), "There's a %d second waittime between kickvotes for each player please wait %d second(s)",
g_Config.m_SvVoteKickDelay,
((m_apPlayers[ClientId]->m_LastKickVote + (m_apPlayers[ClientId]->m_LastKickVote*time_freq()))/time_freq())-(time_get()/time_freq())
g_Config.m_SvVoteKickTimeDelay,
((m_apPlayers[ClientId]->m_Last_KickVote + (m_apPlayers[ClientId]->m_Last_KickVote*time_freq()))/time_freq())-(time_get()/time_freq())
);
SendChatTarget(client_id, chatmsg);
m_apPlayers[ClientId]->m_LastKickVote = time_get();
SendChatTarget(ClientId, chatmsg);
m_apPlayers[ClientId]->m_Last_KickVote = time_get();
return;
}
else if(!g_Config.m_SvVoteKick)
{
SendChatTarget(ClientId, "Server does not allow voting to kick players");
m_apPlayers[ClientId]->m_Last_KickVote = time_get();
return;
}
@ -828,6 +833,7 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId)
if(KickId < 0 || KickId >= MAX_CLIENTS || !m_apPlayers[KickId])
{
SendChatTarget(ClientId, "Invalid client id to kick");
m_apPlayers[ClientId]->m_Last_KickVote = time_get();
return;
}
if(KickId == ClientId)
@ -838,6 +844,7 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId)
if(Server()->IsAuthed(KickId))
{
SendChatTarget(ClientId, "You cant kick admins");
m_apPlayers[ClientId]->m_Last_KickVote = time_get();
char aBufKick[128];
str_format(aBufKick, sizeof(aBufKick), "%s called for vote to kick you", Server()->ClientName(ClientId));
SendChatTarget(KickId, aBufKick);
@ -846,7 +853,7 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId)
str_format(aChatmsg, sizeof(aChatmsg), "%s called for vote to kick '%s'", Server()->ClientName(ClientId), Server()->ClientName(KickId));
str_format(aDesc, sizeof(aDesc), "Kick '%s'", Server()->ClientName(KickId));
if (!g_Config.m_SvVoteKickBantime)
if (!g_Config.m_SvVoteKickBanTime)
str_format(aCmd, sizeof(aCmd), "kick %d", KickId);
else
{
@ -854,6 +861,7 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId)
Server()->GetClientIP(KickId, aBuf, sizeof(aBuf));
str_format(aCmd, sizeof(aCmd), "ban %s %d", aBuf, g_Config.m_SvVoteKickBantime);
}
m_apPlayers[ClientId]->m_Last_KickVote = time_get();
}
if(aCmd[0])

View file

@ -1,5 +1,7 @@
#include <new>
#include <stdio.h>
#include <engine/server.h>
#include <engine/server/server.h>
#include <engine/shared/config.h>
#include "player.h"
@ -229,7 +231,7 @@ void CPlayer::AfkTimer(int new_target_x, int new_target_y)
if(m_Authed) return; // don't kick admins
if(g_Config.m_SvMaxAfkTime == 0) return; // 0 = disabled
if(new_target_x != last_target_x || new_target_y != last_target_y)
if(new_target_x != m_LastTarget_x || new_target_y != m_LastTarget_y)
{
m_LastPlaytime = time_get();
m_LastTarget_x = new_target_x;
@ -249,7 +251,7 @@ void CPlayer::AfkTimer(int new_target_x, int new_target_y)
(int)(g_Config.m_SvMaxAfkTime*0.5),
g_Config.m_SvMaxAfkTime
);
m_pGameServer->SendChatTarget(client_id, m_pAfkMsg);
m_pGameServer->SendChatTarget(m_ClientID, m_pAfkMsg);
m_SentAfkWarning = 1;
} else if(m_SentAfkWarning2 == 0 && m_LastPlaytime < time_get()-time_freq()*(int)(g_Config.m_SvMaxAfkTime*0.9))
{
@ -259,11 +261,12 @@ void CPlayer::AfkTimer(int new_target_x, int new_target_y)
(int)(g_Config.m_SvMaxAfkTime*0.9),
g_Config.m_SvMaxAfkTime
);
m_pGameServer->SendChatTarget(client_id, m_pAfkMsg);
m_pGameServer->SendChatTarget(m_ClientID, m_pAfkMsg);
m_SentAfkWarning = 1;
} else if(last_playtime < time_get()-time_freq()*g_Config.m_SvMaxAfkTime)
} else if(m_LastPlaytime < time_get()-time_freq()*g_Config.m_SvMaxAfkTime)
{
m_pGameServer->Server()->Kick(client_id,"Away from keyboard");
CServer* serv = (CServer*)m_pGameServer->Server();
serv->Kick(m_ClientID,"Away from keyboard");
}
}
}