コード例 #1
0
char* SV_PlayerBannedByip(netadr_t *netadr){	//Gets called in SV_DirectConnect
    ipBanList_t *this;
    int i;

    for(this = &ipBans[0], i = 0; i < 1024; this++, i++){

        if(NET_CompareBaseAdr(netadr, &this->remote)){

            if(Com_GetRealtime() < this->timeout)
            {

                if(this->expire == -1){
                    return va("\nEnforcing prior ban\nPermanent ban issued onto this gameserver\nYou will be never allowed to join this gameserver again\n Your UID is: %i    Banning admin UID is: %i\nReason for this ban:\n%s\n",
                    this->uid,this->adminuid,this->banmsg);

                }else{

                    int remaining = (int)(this->expire - Com_GetRealtime()) +1; //in seconds (+1 for fixing up a display error when only some seconds are remaining)
                    int d = remaining/(60*60*24);
                    remaining = remaining%(60*60*24);
                    int h = remaining/(60*60);
                    remaining = remaining%(60*60);
                    int m = remaining/60;

                    return va("\nEnforcing prior kick/ban\nTemporary ban issued onto this gameserver\nYou are not allowed to rejoin this gameserver for another\n %i days %i hours %i minutes\n Your UID is: %i    Banning admin UID is: %i\nReason for this ban:\n%s\n",
                    d,h,m,this->uid,this->adminuid,this->banmsg);
                }


            }
        }
    }
    return NULL;
}
コード例 #2
0
//duration is in minutes
void SV_PlayerAddBanByip(netadr_t *remote, char *reason, int uid, char* guid, int adminuid, int expire){		//Gets called by future implemented ban-commands and if a prior ban got enforced again

    ipBanList_t *list;
    int i;
    int oldest =	0;
    unsigned int oldestTime = 0;
    int duration;

    if(!remote)
    {
        Com_PrintError("SV_PlayerAddBanByip: IP address is NULL\n");
        return;

    }

    if(!ipbantime || ipbantime->integer == 0)
        return;

    for(list = &ipBans[0], i = 0; i < 1024; list++, i++){	//At first check whether we have already an entry for this player
        if(NET_CompareBaseAdr(remote, &list->remote)){
            break;
        }
	if (list->systime < oldestTime) {
		oldestTime = list->systime;
		oldest = i;
	}
    }

    if(i == 1024){
	 list = &ipBans[oldest];
    }
    list->remote = *remote;

    Q_strncpyz(list->banmsg, reason, 128);

    if(guid && strlen(guid) == 32)
        guid += 24;

    if(guid && strlen(guid) == 8)
    {

        Q_strncpyz(list->guid, guid, sizeof(list->guid));

    }

    list->expire = expire;
    list->uid = uid;
    list->adminuid = adminuid;

    duration = expire - Com_GetRealtime();
    if(duration > ipbantime->integer*60 || expire == -1)
        duration = ipbantime->integer*60;	//Don't ban IPs for more than MAX_IPBAN_MINUTES minutes as they can be shared (Carrier-grade NAT)

    list->systime = Sys_Milliseconds();

    list->timeout = Com_GetRealtime() + duration;

}
コード例 #3
0
void GScr_GetRealTime(){

    if(Scr_GetNumParam()){
        Scr_Error("Usage: getRealTime()\n");
    }
    Scr_AddInt(Com_GetRealtime() - 1325376000);
}
コード例 #4
0
void QDECL SV_PrintAdministrativeLog( const char *fmt, ... ) {

	va_list		argptr;
	char		msg[MAXPRINTMSG];
	char		inputmsg[MAXPRINTMSG];
	struct tm 	*newtime;
	char*		ltime;
	time_t		realtime;

	va_start (argptr,fmt);
	Q_vsnprintf (inputmsg, sizeof(inputmsg), fmt, argptr);
	va_end (argptr);

	Com_UpdateRealtime();
	realtime = Com_GetRealtime();
	newtime = localtime( &realtime );
	ltime = asctime( newtime );
	ltime[strlen(ltime)-1] = 0;

	if(SV_UseUids())
		Com_sprintf(msg, sizeof(msg), "%s - Admin %i with %i power %s\n", ltime, cmdInvoker.currentCmdInvoker, cmdInvoker.currentCmdPower, inputmsg);
	else
		Com_sprintf(msg, sizeof(msg), "%s - Admin %s with %i power %s\n", ltime, cmdInvoker.currentCmdInvokerGuid, cmdInvoker.currentCmdPower, inputmsg);

	Com_PrintAdministrativeLog( msg );

}
コード例 #5
0
void QDECL SV_EnterLeaveLog( const char *fmt, ... ) {

	Sys_EnterCriticalSection(5);

	va_list		argptr;
	char		msg[MAXPRINTMSG];
	char		inputmsg[MAXPRINTMSG];
	struct tm 	*newtime;
	char*		ltime;
	time_t		realtime;

        // logfile
	if ( com_logfile && com_logfile->integer ) {
        // TTimo: only open the qconsole.log if the filesystem is in an initialized state
        // also, avoid recursing in the qconsole.log opening (i.e. if fs_debug is on)

	    va_start (argptr,fmt);
	    Q_vsnprintf (inputmsg, sizeof(inputmsg), fmt, argptr);
	    va_end (argptr);

	    Com_UpdateRealtime();
	    realtime = Com_GetRealtime();
	    newtime = localtime( &realtime );
	    ltime = asctime( newtime );
	    ltime[strlen(ltime)-1] = 0;

	    if ( !enterleavelogfile && FS_Initialized()) {

			enterleavelogfile = FS_FOpenFileAppend( "enterleave.log" );
			// force it to not buffer so we get valid
			if ( enterleavelogfile ){
				FS_ForceFlush(enterleavelogfile);
				FS_Write(va("\nLogfile opened on %s\n\n", ltime), strlen(va("\nLogfile opened on %s\n\n", ltime)), enterleavelogfile);
			}
	    }

	    if ( enterleavelogfile && FS_Initialized()) {
		Com_sprintf(msg, sizeof(msg), "%s: %s\n", ltime, inputmsg);
		FS_Write(msg, strlen(msg), enterleavelogfile);
	    }

	}
	Sys_LeaveCriticalSection(5);
}
コード例 #6
0
void QDECL Com_PrintAdministrativeLog( const char *msg ) {

	Sys_EnterCriticalSection(5);

	struct tm 	*newtime;
	char*		ltime;
	time_t		realtime;

        // logfile
	if ( com_logfile && com_logfile->integer ) {
        // TTimo: only open the qconsole.log if the filesystem is in an initialized state
        //   also, avoid recursing in the qconsole.log opening (i.e. if fs_debug is on)


	    if ( !adminlogfile && FS_Initialized()) {

			Com_UpdateRealtime();
			realtime = Com_GetRealtime();
			newtime = localtime( &realtime );
			ltime = asctime( newtime );
			ltime[strlen(ltime)-1] = 0;


			adminlogfile = FS_FOpenFileAppend( "adminactions.log" );
			// force it to not buffer so we get valid
			if ( adminlogfile ){
				FS_ForceFlush(adminlogfile);
				FS_Write(va("\nLogfile opened on %s\n\n", ltime), strlen(va("\nLogfile opened on %s\n\n", ltime)), adminlogfile);
			}
	    }

	    if ( adminlogfile && FS_Initialized())
	    {
		FS_Write(msg, strlen(msg), adminlogfile);
	    }

	}
	Sys_LeaveCriticalSection(5);
}
コード例 #7
0
ファイル: sv_ingameadmin.c プロジェクト: BraXi/CoD4X18-Server
void QDECL SV_PrintAdministrativeLog( const char *fmt, ... ) {

	va_list		argptr;
	char		msg[MAXPRINTMSG];
	char		inputmsg[MAXPRINTMSG];
	struct tm 	*newtime;
	char*		ltime;
	time_t		realtime;

	va_start (argptr,fmt);
	Q_vsnprintf (inputmsg, sizeof(inputmsg), fmt, argptr);
	va_end (argptr);

	Com_UpdateRealtime();
	realtime = Com_GetRealtime();
	newtime = localtime( &realtime );
	ltime = asctime( newtime );
	ltime[strlen(ltime)-1] = 0;

	Com_sprintf(msg, sizeof(msg), "%s - Admin %i with %i power %s\n", ltime, Cmd_GetInvokerUID(), Cmd_GetInvokerPower(), inputmsg);

	Com_PrintAdministrativeLog( msg );

}
コード例 #8
0
qboolean HTTPCreateWebadminMessage(ftRequest_t* request, msg_t* msg, char* sessionkey, httpPostVals_t* values)
{
	byte *buf;
	char qpath[MAX_QPATH];
	int len;
	const char *session;
	char banmsg[1024];

	buf = NULL;

	MSG_Init(msg, buf, 0);
	Com_Printf("URL: %s\n", request->url);
	if(!Q_strncmp(request->url, "/files", 6))
	{
		if(request->url[6] != '/' || request->url[7] == '\0')
		{
			return qfalse;
		}
		Com_sprintf(qpath, sizeof(qpath), "/webadmindata/%s", &request->url[7]);

		if(strstr(qpath, "..") != NULL || strstr(qpath, "::") != NULL)
		{
			return qfalse;
		}
		len = FS_ReadFile(qpath, (void**)&buf);

		if(len < 0)
		{
			return qfalse;
		}
		msg->data = buf;
		msg->cursize = len;
		msg->maxsize = len;
		FS_FreeFileKeepBuf( );
		return qtrue;
	}

	len = 0x20000;

	buf = Z_Malloc(len);
	if(buf == NULL)
	{
		return qfalse;
	}

	msg->data = buf;
	msg->cursize = 0;
	msg->maxsize = len;

	if (Q_stricmpn(request->url, "/webadmin", 9))
	{
		Webadmin_BuildMessage(msg, NULL, qfalse, NULL ,request->url, values);
		return qtrue;
	}

	qboolean invalidlogin = qfalse;
	const char* username = NULL;
	const char* password = NULL;


	if(SV_PlayerBannedByip(&request->remote, banmsg, sizeof(banmsg)))
	{
		Webadmin_BuildMessage(msg, NULL, qfalse, banmsg, request->url, values);
		return qtrue;
	}

	username = Auth_FindSessionID(sessionkey);

	if(username == NULL)
	{

		username = HTTP_GetFormDataItem(values, "username");
		password = HTTP_GetFormDataItem(values, "password");

		if(username[0] && password[0])
		{
			session = Auth_GetSessionId(username, password);
			if(session == NULL)
			{
				Com_Printf("^1Invalid login\n");
				invalidlogin = qtrue;
				SV_PlayerAddBanByip(&request->remote, "Invalid login attempt. You have to wait 20 seconds", Com_GetRealtime() + 10);
				username = NULL;
			}else {
				Com_Printf("^2Successful login with username: %s\n", username);
			}


		}else {
			Com_Printf("No login!\n");
			session = NULL;
			username = NULL;
		}

		/* not longer than 127 or overflow */
		if(session != NULL)
		{
			strcpy(sessionkey, session);
		}
	}else{
		Com_Printf("Already logged in as: %s\n", username);
	}

	Webadmin_BuildMessage(msg, username, invalidlogin, NULL, request->url, values);

	return qtrue;
}
コード例 #9
0
tcpclientstate_t HL2Rcon_SourceRconAuth(netadr_t *from, msg_t *msg, int *connectionId){

	int packetlen;
	int packettype;
	int packetid;
	char* loginstring;
	char* username;
	char* password;
	byte msgbuf[32];
	msg_t sendmsg;
	rconUser_t* user;
	int i;
	char buf[MAX_STRING_CHARS];
	char stringlinebuf[MAX_STRING_CHARS];

	MSG_BeginReading(msg);
	packetlen = MSG_ReadLong(msg);

	if(packetlen != msg->cursize - 4){//Not a source rcon packet

		Com_Printf("Not a source rcon packet: len %d size %d\n", packetlen, msg->cursize);

		return TCP_AUTHNOTME;
	}
	packetid = MSG_ReadLong(msg);

	packettype = MSG_ReadLong(msg);

	if(packettype != SERVERDATA_AUTH)//Not a source rcon auth-packet
		return TCP_AUTHNOTME;

	if(SV_PlayerBannedByip(from, buf, sizeof(buf))){
		return TCP_AUTHBAD;
	}
	
	MSG_Init(&sendmsg, msgbuf, sizeof(msgbuf));
	MSG_WriteLong(&sendmsg, 10);
	MSG_WriteLong(&sendmsg, 0);
	MSG_WriteLong(&sendmsg, SERVERDATA_RESPONSE_VALUE);
	MSG_WriteShort(&sendmsg, 0);
	if(NET_SendData(from->sock, &sendmsg) < 1)
	{
		return TCP_AUTHBAD;
	}

	MSG_Init(&sendmsg, msgbuf, sizeof(msgbuf));
	MSG_WriteLong(&sendmsg, 10);

	loginstring = MSG_ReadStringLine(msg, stringlinebuf, sizeof(stringlinebuf));

	Cmd_TokenizeString(loginstring);

	if(Cmd_Argc() != 2){
		goto badrcon;
	}
	username = Cmd_Argv(0);
	password = Cmd_Argv(1);

	if(strlen(password) < 6){
		goto badrcon;
	}

	if(Auth_Authorize(username, password) < 0)
	{
		goto badrcon;
	}

	Com_Printf("Rcon login from: %s Name: %s\n", NET_AdrToString (from), username);

	Cmd_EndTokenizedString();

	for(i = 0, user = sourceRcon.activeRconUsers; i < MAX_RCONUSERS; i++, user++){
		if(user->remote.type == NA_BAD)
			break;
	}

	if(i == MAX_RCONUSERS){
		return TCP_AUTHBAD; //Close connection
	}


	user->remote = *from;
	user->uid = Auth_GetUID(username);
//	user->rconPower = login->power;
	Q_strncpyz(user->rconUsername, username, sizeof(user->rconUsername));
	user->streamchat = 0;
	user->streamlog = 0;
	user->lastpacketid = packetid;
	*connectionId = i;

	MSG_WriteLong(&sendmsg, user->lastpacketid);
	MSG_WriteLong(&sendmsg, SERVERDATA_AUTH_RESPONSE);
	MSG_WriteShort(&sendmsg, 0);
	if(NET_SendData(from->sock, &sendmsg) < 1)
	{
		return TCP_AUTHBAD;
	}

	return TCP_AUTHSUCCESSFULL;


badrcon:
	Cmd_EndTokenizedString();
	Com_Printf ("Bad rcon from %s (TCP)\n", NET_AdrToString (from) );
	//Don't allow another attempt for 20 seconds
	SV_PlayerAddBanByip(from, "Bad rcon", 0, NULL, 0, Com_GetRealtime() + 20);

	MSG_Init(&sendmsg, msgbuf, sizeof(msgbuf));
	MSG_WriteLong(&sendmsg, 10);
	MSG_WriteLong(&sendmsg, -1);
	MSG_WriteLong(&sendmsg, SERVERDATA_AUTH_RESPONSE);
	MSG_WriteShort(&sendmsg, 0);
	NET_SendData(from->sock, &sendmsg);
	return TCP_AUTHBAD;

}
コード例 #10
0
char* SV_PlayerIsBanned(int uid, char* pbguid, netadr_t *addr){

  banList_t *this;
  int i;

  this = banlist;
  if(!this)
        return NULL;


  if(uid > 0){
    for(i = 0 ; i < current_banindex; this++, i++){

        if(this->playeruid == uid){

            if(this->expire == (time_t)-1){
                SV_PlayerAddBanByip(addr, this->reason, this->playeruid, pbguid, this->adminuid, -1);
                return va("\nEnforcing prior ban\nPermanent ban issued onto this gameserver\nYou will be never allowed to join this gameserver again\n Your UID is: %i    Banning admin UID is: %i\nReason for this ban:\n%s\n",
                this->playeruid,this->adminuid,this->reason);
            }

            if(this->expire > Com_GetRealtime()){

		int remaining = (int)(this->expire - Com_GetRealtime());
                SV_PlayerAddBanByip(addr, this->reason, this->playeruid, pbguid, this->adminuid, this->expire);
		int d = remaining/(60*60*24);
		remaining = remaining%(60*60*24);
		int h = remaining/(60*60);
		remaining = remaining%(60*60);
		int m = remaining/60;

                return va("\nEnforcing prior kick/ban\nTemporary ban issued onto this gameserver\nYou are not allowed to rejoin this gameserver for another\n %i days %i hours %i minutes\n Your UID is: %i    Banning admin UID is: %i\nReason for this ban:\n%s\n",
                d,h,m,this->playeruid,this->adminuid,this->reason);
            }
        }
    }

  }else if(pbguid != NULL && strlen(pbguid) == 32){


    for(i = 0 ; i < current_banindex; this++, i++){

        if(!Q_strncmp(this->pbguid, &pbguid[24], 8)){

            if(this->expire == (time_t)-1){
                return va("Permanent ban issued onto this gameserver\nYou will be never allowed to join this gameserver again\n Your GUID is: %s\nReason for this ban:\n%s\n",
                this->pbguid, this->reason);
            }

            if(this->expire > Com_GetRealtime()){

		int remaining = (int)(this->expire - Com_GetRealtime());
		int d = remaining/(60*60*24);
		remaining = remaining%(60*60*24);
		int h = remaining/(60*60);
		remaining = remaining%(60*60);
		int m = remaining/60;

                return va("Temporary ban issued onto this gameserver\nYou are not allowed to rejoin this gameserver for another\n %i days %i hours %i minutes\n Your GUID is: %s\nReason for this ban:\n%s\n",
                d,h,m, this->pbguid, this->reason);
            }

        }
    }
  }
  return NULL;

}