Ejemplo n.º 1
0
void JSONRPCRequest::parse(const UniValue& valRequest)
{
    // Parse request
    if (!valRequest.isObject())
        throw JSONRPCError(RPC_INVALID_REQUEST, "Invalid Request object");
    const UniValue& request = valRequest.get_obj();

    // Parse id now so errors from here on will have the id
    id = find_value(request, "id");

    // Parse method
    UniValue valMethod = find_value(request, "method");
    if (valMethod.isNull())
        throw JSONRPCError(RPC_INVALID_REQUEST, "Missing method");
    if (!valMethod.isStr())
        throw JSONRPCError(RPC_INVALID_REQUEST, "Method must be a string");
    strMethod = valMethod.get_str();
    if (fLogIPs)
        LogPrint(BCLog::RPC, "ThreadRPCServer method=%s user=%s peeraddr=%s\n", SanitizeString(strMethod),
            this->authUser, this->peerAddr);
    else
        LogPrint(BCLog::RPC, "ThreadRPCServer method=%s user=%s\n", SanitizeString(strMethod), this->authUser);

    // Parse params
    UniValue valParams = find_value(request, "params");
    if (valParams.isArray() || valParams.isObject())
        params = valParams;
    else if (valParams.isNull())
        params = UniValue(UniValue::VARR);
    else
        throw JSONRPCError(RPC_INVALID_REQUEST, "Params must be an array or object");
}
Ejemplo n.º 2
0
void Gr(FILE *consc,char *from, enum associations assoc, char *to, char *context)
{
 char *sfrom = SanitizeString(from);
 char *sto = SanitizeString(to);
 char *scontext = SanitizeString(context);

 if (strcmp(sfrom,sto) == 0)
    {
    return;
    }
 
 if (context && strlen(context) > 1)
    {
    fprintf(consc,"(%s,%d,%s,%s,%s,%s)\n",sfrom,A[assoc].type,A[assoc].fwd,sto,A[assoc].bwd,scontext);
    // Simen fprintf(consc,"(%s,%s,%s,%s)\n",Aname[assoc],sfrom,sto,scontext);
    }
 else
    {
    fprintf(consc,"(%s,%d,%s,%s,%s,%s)\n",sfrom,A[assoc].type,A[assoc].fwd,sto,A[assoc].bwd,ALL_CONTEXTS);
    // Simen fprintf(consc,"(%s,%s,%d,%s,%s)\n",Aname[assoc],sfrom,sto,ALL_CONTEXTS);
    }

 free(sfrom);
 free(sto);
 free(scontext);
}
Ejemplo n.º 3
0
void TorController::add_onion_cb(TorControlConnection& _conn, const TorControlReply& reply)
{
    if (reply.code == 250) {
        LogPrint(BCLog::TOR, "tor: ADD_ONION successful\n");
        BOOST_FOREACH(const std::string &s, reply.lines) {
            std::map<std::string,std::string> m = ParseTorReplyMapping(s);
            std::map<std::string,std::string>::iterator i;
            if ((i = m.find("ServiceID")) != m.end())
                service_id = i->second;
            if ((i = m.find("PrivateKey")) != m.end())
                private_key = i->second;
        }
        if (service_id.empty()) {
            LogPrintf("tor: Error parsing ADD_ONION parameters:\n");
            for (const std::string &s : reply.lines) {
                LogPrintf("    %s\n", SanitizeString(s));
            }
            return;
        }
        service = LookupNumeric(std::string(service_id+".onion").c_str(), GetListenPort());
        LogPrintf("tor: Got service ID %s, advertising service %s\n", service_id, service.ToString());
        if (WriteBinaryFile(GetPrivateKeyFile(), private_key)) {
            LogPrint(BCLog::TOR, "tor: Cached service private key to %s\n", GetPrivateKeyFile().string());
        } else {
            LogPrintf("tor: Error writing service private key to %s\n", GetPrivateKeyFile().string());
        }
        AddLocal(service, LOCAL_MANUAL);
        // ... onion requested - keep connection open
    } else if (reply.code == 510) { // 510 Unrecognized command
Ejemplo n.º 4
0
void TorController::authchallenge_cb(TorControlConnection& _conn, const TorControlReply& reply)
{
    if (reply.code == 250) {
        LogPrint(BCLog::TOR, "tor: SAFECOOKIE authentication challenge successful\n");
        std::pair<std::string,std::string> l = SplitTorReplyLine(reply.lines[0]);
        if (l.first == "AUTHCHALLENGE") {
            std::map<std::string,std::string> m = ParseTorReplyMapping(l.second);
            if (m.empty()) {
                LogPrintf("tor: Error parsing AUTHCHALLENGE parameters: %s\n", SanitizeString(l.second));
                return;
            }
            std::vector<uint8_t> serverHash = ParseHex(m["SERVERHASH"]);
            std::vector<uint8_t> serverNonce = ParseHex(m["SERVERNONCE"]);
            LogPrint(BCLog::TOR, "tor: AUTHCHALLENGE ServerHash %s ServerNonce %s\n", HexStr(serverHash), HexStr(serverNonce));
            if (serverNonce.size() != 32) {
                LogPrintf("tor: ServerNonce is not 32 bytes, as required by spec\n");
                return;
            }

            std::vector<uint8_t> computedServerHash = ComputeResponse(TOR_SAFE_SERVERKEY, cookie, clientNonce, serverNonce);
            if (computedServerHash != serverHash) {
                LogPrintf("tor: ServerHash %s does not match expected ServerHash %s\n", HexStr(serverHash), HexStr(computedServerHash));
                return;
            }

            std::vector<uint8_t> computedClientHash = ComputeResponse(TOR_SAFE_CLIENTKEY, cookie, clientNonce, serverNonce);
            _conn.Command("AUTHENTICATE " + HexStr(computedClientHash), std::bind(&TorController::auth_cb, this, std::placeholders::_1, std::placeholders::_2));
        } else {
            LogPrintf("tor: Invalid reply to AUTHCHALLENGE\n");
        }
    } else {
        LogPrintf("tor: SAFECOOKIE authentication challenge failed\n");
    }
}
Ejemplo n.º 5
0
void GrQ(FILE *consc,char *from, enum associations assoc, double to, char *context)
{
 char *sfrom = SanitizeString(from);
 char *scontext = SanitizeString(context);

 if (context && strlen(context) > 1)
    {
    fprintf(consc,"(%s,%d,%s,%.2lf,%s,%s)\n",sfrom,A[assoc].type,A[assoc].fwd,to,A[assoc].bwd,scontext);
    }
 else
    {
    fprintf(consc,"(%s,%d,%s,%.2lf,%s,%s)\n",sfrom,A[assoc].type,A[assoc].fwd,to,A[assoc].bwd,ALL_CONTEXTS);
    }
 
 free(sfrom);
 free(scontext); 
}
Ejemplo n.º 6
0
u8 *GetTrainerLoseText(void)
{
    const u8 *str;

    if (gTrainerBattleOpponent == SECRET_BASE_OPPONENT)
        str = GetSecretBaseTrainerLoseText();
    else
        str = sTrainerDefeatSpeech;

    StringExpandPlaceholders(gStringVar4, SanitizeString(str));
    return gStringVar4;
}
Ejemplo n.º 7
0
/*
==================
ClientNumbersFromString

Sets plist to an array of integers that represent client numbers that have 
names that are a partial match for s. List is terminated by a -1.

Returns number of matching clientids.
==================
*/
int ClientNumbersFromString( const char *s, int *plist) {
    gclient_t *p;
    int i, found = 0;
    char s2[MAX_STRING_CHARS];
    char n2[MAX_STRING_CHARS];
    char *m;
    qboolean is_slot = qtrue;

    *plist = -1;

    // if a number is provided, it might be a slot # 
    for(i=0; i<(int)strlen(s); i++) { 
        if(s[i] < '0' || s[i] > '9') {
            is_slot = qfalse;
            break;
        }
    }
    if(is_slot) {
        i = atoi(s);
        if(i >= 0 && i < level.maxclients) {
            p = &level.clients[i];
            if(p->pers.connected == CON_CONNECTED ||
                p->pers.connected == CON_CONNECTING) {

                    *plist++ = i;
                    *plist = -1;
                    return 1;
            }
        }
    }

    // now look for name matches
    SanitizeConstString(s, s2, qtrue);
    if(strlen(s2) < 1) return 0;
    for(i=0; i < level.maxclients; i++) {
        p = &level.clients[i];
        if(p->pers.connected != CON_CONNECTED &&
            p->pers.connected != CON_CONNECTING) {

                continue;
        }
        SanitizeString(p->pers.netname, n2, qtrue);
        m = strstr(n2, s2);
        if(m != NULL) {
            *plist++ = i;
            found++;
        }
    }
    *plist = -1;
    return found;
}
Ejemplo n.º 8
0
/*
==================
ClientNumberFromString

Returns a player number for either a number or name string
Returns -1 if invalid
==================
*/
int ClientNumberFromString( gentity_t *to, char *s ) {
	gclient_t	*cl;
	int			idnum;
	char		s2[MAX_STRING_CHARS];
	char		n2[MAX_STRING_CHARS];

	// numeric values are just slot numbers
	if (s[0] >= '0' && s[0] <= '9') {
		idnum = atoi( s );
		if ( idnum < 0 || idnum >= level.maxclients ) {
			gi.SendServerCommand( to-g_entities, "print \"Bad client slot: %i\n\"", idnum);
			return -1;
		}

		cl = &level.clients[idnum];
		if ( cl->pers.connected != CON_CONNECTED ) {
			gi.SendServerCommand( to-g_entities, "print \"Client %i is not active\n\"", idnum);
			return -1;
		}
		return idnum;
	}

	// check for a name match
	SanitizeString( s, s2 );
	for ( idnum=0,cl=level.clients ; idnum < level.maxclients ; idnum++,cl++ ) {
		if ( cl->pers.connected != CON_CONNECTED ) {
			continue;
		}
		SanitizeString( cl->pers.netname, n2 );
		if ( !strcmp( n2, s2 ) ) {
			return idnum;
		}
	}

	gi.SendServerCommand( to-g_entities, "print \"User %s is not on the server\n\"", s);
	return -1;
}
Ejemplo n.º 9
0
qboolean G_CensorName(char *testname, char *userinfo, int clientNum)
{
    char censoredName[MAX_NETNAME];
    char name[MAX_NETNAME];
    Q_strncpyz(name, testname, sizeof(name));
    SanitizeString(name, censoredName, qtrue);
    if (G_CensorText(censoredName, &censorNamesDictionary))
    {
        Q_strncpyz(testname, censoredName, sizeof(censoredName));
        if (g_censorPenalty.integer & CNSRPNLTY_KICK)
        {
            trap_DropClient(clientNum,
                            va("Name censor: Please change your name."),
                            0);
            return qtrue;
        }
    }
    return qfalse;
}
Ejemplo n.º 10
0
static const u8 *GetTrainerIntroSpeech(void)
{
    return SanitizeString(sTrainerIntroSpeech);
}
Ejemplo n.º 11
0
// Prints current player match info.
//  --> FIXME: put the pretty print on the client
void G_printMatchInfo(gentity_t *ent)
{
	int       i, j, cnt = 0, eff;
	int       tot_timex, tot_timel, tot_kills, tot_deaths, tot_gp, tot_sk, tot_tk, tot_dg, tot_dr, tot_tdg, tot_tdr, tot_xp;
	gclient_t *cl;
	char      *ref;
	char      n2[MAX_STRING_CHARS];

	for (i = TEAM_AXIS; i <= TEAM_ALLIES; i++)
	{
		if (!TeamCount(-1, i))
		{
			continue;
		}

		tot_timex  = 0;
		tot_timel  = 0;
		tot_kills  = 0;
		tot_deaths = 0;
		tot_sk     = 0;
		tot_tk     = 0;
		tot_dg     = 0;
		tot_dr     = 0;
		tot_tdg    = 0;
		tot_tdr    = 0;
		tot_gp     = 0;
		tot_xp     = 0;

		CP("sc \"\n\"");
		CP("sc \"^7TEAM   Player          ^1TmX ^4TmL ^7Kll Dth  SK  TK Eff  ^3GP^7    ^2DG    ^1DR  ^6TDG  ^4TDR  ^3Score\n\"");
		CP("sc \"^7-----------------------------------------------------------------------------------\n\"");

		for (j = 0; j < level.numPlayingClients; j++)
		{
			cl = level.clients + level.sortedClients[j];

			if (cl->pers.connected != CON_CONNECTED || cl->sess.sessionTeam != i)
			{
				continue;
			}

			SanitizeString(cl->pers.netname, n2, qfalse);
			n2[15] = 0;

			ref         = "^7";
			tot_timex  += cl->sess.time_axis;
			tot_timel  += cl->sess.time_allies;
			tot_kills  += cl->sess.kills;
			tot_deaths += cl->sess.deaths;
			tot_sk     += cl->sess.selfkills;
			tot_tk     += cl->sess.team_kills;
			tot_dg     += cl->sess.damage_given;
			tot_dr     += cl->sess.damage_received;
			tot_tdg    += cl->sess.team_damage_given;
			tot_tdr    += cl->sess.team_damage_received;
			tot_gp     += cl->sess.game_points;
			tot_xp     += cl->ps.persistant[PERS_SCORE];

			eff = (cl->sess.deaths + cl->sess.kills == 0) ? 0 : 100 * cl->sess.kills / (cl->sess.deaths + cl->sess.kills);
			if (eff < 0)
			{
				eff = 0;
			}

			if (ent->client == cl ||
			    (ent->client->sess.sessionTeam == TEAM_SPECTATOR &&
			     ent->client->sess.spectatorState == SPECTATOR_FOLLOW &&
			     ent->client->sess.spectatorClient == level.sortedClients[j]))
			{
				ref = "^3";
			}

			cnt++;
			CP(va("sc \"%-10s %s%-15s^1%4d^4%4d^3%4d%4d%4d%4d%s%4d^3%4d^2%6d^1%6d^6%5d^4%5d^3%7d\n\"",
			      aTeams[i],
			      ref,
			      n2,
			      cl->sess.time_axis / 60000,
			      cl->sess.time_allies / 60000,
			      cl->sess.kills,
			      cl->sess.deaths,
			      cl->sess.selfkills,
			      cl->sess.team_kills,
			      ref,
			      eff,
			      cl->sess.game_points - (cl->sess.kills * WOLF_FRAG_BONUS),
			      cl->sess.damage_given,
			      cl->sess.damage_received,
			      cl->sess.team_damage_given,
			      cl->sess.team_damage_received,
			      cl->ps.persistant[PERS_SCORE]));
		}

		eff = (tot_kills + tot_deaths == 0) ? 0 : 100 * tot_kills / (tot_kills + tot_deaths);
		if (eff < 0)
		{
			eff = 0;
		}

		CP("sc \"^7------------------------------------------- ---------------------------------------\n\"");
		CP(va("sc \"%-10s ^5%-15s^1%4d^4%4d^5%4d%4d%4d%4d^5%4d^3%4d^2%6d^1%6d^6%5d^4%5d^3%7d\n\"",
		      aTeams[i],
		      "Totals",
		      tot_timex / 60000,
		      tot_timel / 60000,
		      tot_kills,
		      tot_deaths,
		      tot_sk,
		      tot_tk,
		      eff,
		      tot_gp - (tot_kills * WOLF_FRAG_BONUS),
		      tot_dg,
		      tot_dr,
		      tot_tdg,
		      tot_tdr,
		      tot_xp));
	}

	CP(va("sc \"%s\n\n\" 0", ((!cnt) ? "^3\nNo scores to report." : "")));
}
Ejemplo n.º 12
0
// ************** PLAYERS
//
// Show client info
void G_players_cmd(gentity_t *ent, unsigned int dwCommand, qboolean fValue)
{
	int i, idnum, max_rate, cnt=0, tteam;
	int user_rate, user_snaps, bots = 0;
	gclient_t *cl;
	gentity_t *cl_ent;
	char n2[MAX_NETNAME], ready[16], ref[16], ign[16], rate[256];
	char *s, *tc, *coach, userinfo[MAX_INFO_STRING];


	if(g_gamestate.integer == GS_PLAYING) {
		if(ent) {
			CP("print \"\n^3 ID^1 : ^3Player                    Nudge  Rate  MaxPkts  Snaps\n\"");
			CP(  "print \"^1-----------------------------------------------------------^7\n\"");
		} else {
			G_Printf(" ID : Player                    Nudge  Rate  MaxPkts  Snaps\n");
			G_Printf("-----------------------------------------------------------\n");
		}
	} else {
		if(ent) {
			CP("print \"\n^3Status^1   : ^3ID^1 : ^3Player                    Nudge  Rate  MaxPkts  Snaps\n\"");
			CP(  "print \"^1---------------------------------------------------------------------^7\n\"");
		} else {
			G_Printf("Status   : ID : Player                    Nudge  Rate  MaxPkts  Snaps\n");
			G_Printf("---------------------------------------------------------------------\n");
		}
	}

	max_rate = trap_Cvar_VariableIntegerValue("sv_maxrate");

	for(i=0; i<level.numConnectedClients; i++) {
		idnum = level.sortedClients[i];//level.sortedNames[i];
		cl = &level.clients[idnum];
		cl_ent = g_entities + idnum;

		SanitizeString(cl->pers.netname, n2, qtrue);
		n2[26] = 0;
		ref[0] = 0;
		ign[0] = 0;
		ready[0] = 0;

		// Rate info
		if(cl_ent->r.svFlags & SVF_BOT) {
			strcpy(rate, va("%s%s%s%s", "[BOT]", " -----", "       --", "     --"));
			bots++;
		} else if(cl->pers.connected == CON_CONNECTING) {
			strcpy(rate, va("%s", "^3>>> CONNECTING <<<"));
		} else {
			trap_GetUserinfo( idnum, userinfo, sizeof(userinfo));
			s = Info_ValueForKey( userinfo, "rate" );
			user_rate = (max_rate > 0 && atoi(s) > max_rate) ? max_rate : atoi(s);
			s = Info_ValueForKey( userinfo, "snaps" );
			user_snaps = atoi(s);

			strcpy(rate, va("%5d%6d%9d%7d", cl->pers.clientTimeNudge, user_rate, cl->pers.clientMaxPackets, user_snaps));
		}

		if(g_gamestate.integer != GS_PLAYING) {
			// Dens: bots aren't counted, but specs are since changeset 1469
			if((g_entities[idnum].r.svFlags & SVF_BOT) || cl->pers.connected == CON_CONNECTING)
				strcpy(ready, ((ent) ? "^5--------^1 :" : "-------- :"));
			else if(cl->pers.ready)
				strcpy(ready, ((ent) ? "^3(READY)^1  :" : "(READY)  :"));
			else
				strcpy(ready, ((ent) ? "NOTREADY^1 :" : "NOTREADY :"));
		}

		if(cl->sess.referee) strcpy(ref, "REF ");

		// pheno: mark ignored clients
		if ( COM_BitCheck(ent->client->sess.ignoreClients, idnum) ) {
			strcpy(ign, (( ent ) ? "^8I" : "I"));
		}

		if(cl->sess.coach_team) {
			tteam = cl->sess.coach_team;
			coach = (ent) ? "^3C" : "C";
		} else {
			tteam = cl->sess.sessionTeam;
			coach = " ";
		}

		tc = (ent) ? "^7 " : " ";
		if(g_gametype.integer >= GT_WOLF) {
			if(tteam == TEAM_AXIS) tc = (ent) ? "^1X^7" : "X";
			if(tteam == TEAM_ALLIES) tc = (ent) ? "^4L^7" : "L";
		}

		if(ent) CP(va("print \"%s%s%2d%s^1:%s %-26s^7%s  ^3%s%s\n\"", ready, tc, idnum, coach, ((ref[0])?"^3":"^7"), n2, rate, ref, ign));
		else G_Printf("%s%s%2d%s: %-26s%s  %s%s\n", ready, tc, idnum, coach, n2, rate, ref, ign);

		cnt++;
	}

	if(ent) CP(va("print \"\n^3%2d^7 total players (^3%2d^7 humans, ^3%2d^7 bots)\n\n\"",
		cnt, cnt - bots, bots));
	else G_Printf("\n%2d total players (%2d humans, %2d bots\n\n", cnt, cnt - bots, bots);

	// Team speclock info
	if(g_gametype.integer >= GT_WOLF) {
		for(i=TEAM_AXIS; i<=TEAM_ALLIES; i++) {
			if(teamInfo[i].spec_lock) {
				if(ent) CP(va("print \"** %s team is speclocked.\n\"", aTeams[i]));
				else G_Printf("** %s team is speclocked.\n", aTeams[i]);
			}
		}
	}
}
Ejemplo n.º 13
0
bool CMasternodeBroadcast::CheckAndUpdate(int& nDos)
{
    nDos = 0;

    // make sure signature isn't in the future (past is OK)
    if (sigTime > GetAdjustedTime() + 60 * 60) {
        LogPrintf("mnb - Signature rejected, too far into the future %s\n", vin.ToString());
        nDos = 1;
        return false;
    }

    if(protocolVersion < masternodePayments.GetMinMasternodePaymentsProto()) {
        LogPrintf("mnb - ignoring outdated Masternode %s protocol version %d\n", vin.ToString(), protocolVersion);
        return false;
    }

    CScript pubkeyScript;
    pubkeyScript = GetScriptForDestination(pubkey.GetID());

    if(pubkeyScript.size() != 25) {
        LogPrintf("mnb - pubkey the wrong size\n");
        nDos = 100;
        return false;
    }

    CScript pubkeyScript2;
    pubkeyScript2 = GetScriptForDestination(pubkey2.GetID());

    if(pubkeyScript2.size() != 25) {
        LogPrintf("mnb - pubkey2 the wrong size\n");
        nDos = 100;
        return false;
    }

    if(!vin.scriptSig.empty()) {
        LogPrintf("mnb - Ignore Not Empty ScriptSig %s\n",vin.ToString());
        return false;
    }

    std::string strMessage;
    std::string errorMessage = "";

    if(protocolVersion < 70201) {
        std::string vchPubKey(pubkey.begin(), pubkey.end());
        std::string vchPubKey2(pubkey2.begin(), pubkey2.end());
        strMessage = addr.ToString(false) + boost::lexical_cast<std::string>(sigTime) +
                        vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion);

        LogPrint("masternode", "mnb - sanitized strMessage: %s, pubkey address: %s, sig: %s\n",
            SanitizeString(strMessage), CBitcoinAddress(pubkey.GetID()).ToString(),
            EncodeBase64(&sig[0], sig.size()));

        if(!darkSendSigner.VerifyMessage(pubkey, sig, strMessage, errorMessage)){
            if (addr.ToString() != addr.ToString(false))
            {
                // maybe it's wrong format, try again with the old one
                strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) +
                                vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion);

                LogPrint("masternode", "mnb - sanitized strMessage: %s, pubkey address: %s, sig: %s\n",
                    SanitizeString(strMessage), CBitcoinAddress(pubkey.GetID()).ToString(),
                    EncodeBase64(&sig[0], sig.size()));

                if(!darkSendSigner.VerifyMessage(pubkey, sig, strMessage, errorMessage)){
                    // didn't work either
                    LogPrintf("mnb - Got bad Masternode address signature, sanitized error: %s\n", SanitizeString(errorMessage));
                    // there is a bug in old MN signatures, ignore such MN but do not ban the peer we got this from
                    return false;
                }
            } else {
                // nope, sig is actually wrong
                LogPrintf("mnb - Got bad Masternode address signature, sanitized error: %s\n", SanitizeString(errorMessage));
                // there is a bug in old MN signatures, ignore such MN but do not ban the peer we got this from
                return false;
            }
        }
    } else {
        strMessage = addr.ToString(false) + boost::lexical_cast<std::string>(sigTime) +
                        pubkey.GetID().ToString() + pubkey2.GetID().ToString() +
                        boost::lexical_cast<std::string>(protocolVersion);

        LogPrint("masternode", "mnb - strMessage: %s, pubkey address: %s, sig: %s\n",
            strMessage, CBitcoinAddress(pubkey.GetID()).ToString(), EncodeBase64(&sig[0], sig.size()));

        if(!darkSendSigner.VerifyMessage(pubkey, sig, strMessage, errorMessage)){
            LogPrintf("mnb - Got bad Masternode address signature, error: %s\n", errorMessage);
            nDos = 100;
            return false;
        }
    }

    if(Params().NetworkID() == CBaseChainParams::MAIN) {
        if(addr.GetPort() != 9887) return false;
    } else if(addr.GetPort() == 9887) return false;

    //search existing Masternode list, this is where we update existing Masternodes with new mnb broadcasts
    CMasternode* pmn = mnodeman.Find(vin);

    // no such masternode, nothing to update
    if(pmn == NULL) return true ;
    else {
        // this broadcast older than we have, it's bad. 
        if(pmn->sigTime > sigTime) {
            LogPrintf("mnb - Bad sigTime %d for Masternode %20s %105s (existing broadcast is at %d)\n",
                          sigTime, addr.ToString(), vin.ToString(), pmn->sigTime);
            return false;
        }
        // masternode is not enabled yet/already, nothing to update
        if(!pmn->IsEnabled()) return true;
    }

    // mn.pubkey = pubkey, IsVinAssociatedWithPubkey is validated once below,
    //   after that they just need to match
    if(pmn->pubkey == pubkey && !pmn->IsBroadcastedWithin(MASTERNODE_MIN_MNB_SECONDS)) {
        //take the newest entry
        LogPrintf("mnb - Got updated entry for %s\n", addr.ToString());
        if(pmn->UpdateFromNewBroadcast((*this))){
            pmn->Check();
            if(pmn->IsEnabled()) Relay();
        }
        masternodeSync.AddedMasternodeList(GetHash());
    }

    return true;
}
Ejemplo n.º 14
0
static const u8 *GetTrainerNonBattlingSpeech(void)
{
    return SanitizeString(sTrainerCannotBattleSpeech);
}
Ejemplo n.º 15
0
// Show client info
void G_players_cmd(gentity_t *ent, unsigned int dwCommand, qboolean fValue)
{
	int       i, idnum, max_rate, cnt = 0, tteam;
	int       user_rate, user_snaps;
	gclient_t *cl;
	gentity_t *cl_ent;
	char      n2[MAX_NETNAME], ready[16], ref[16], rate[256];
	char      *s, *tc, *coach, userinfo[MAX_INFO_STRING];

	if (g_gamestate.integer == GS_PLAYING)
	{
		if (ent)
		{
			CP("print \"^7 ID : Player                    Nudge  Rate  MaxPkts  Snaps\n\"");
			CP("print \"^7-----------------------------------------------------------\n\"");
		}
		else
		{
			G_Printf(" ID : Player                    Nudge  Rate  MaxPkts  Snaps\n");
			G_Printf("-----------------------------------------------------------\n");
		}
	}
	else
	{
		if (ent)
		{
			CP("print \"^7Status   : ID : Player                    Nudge  Rate  MaxPkts  Snaps\n\"");
			CP("print \"^7---------------------------------------------------------------------\n\"");
		}
		else
		{
			G_Printf("Status   : ID : Player                    Nudge  Rate  MaxPkts  Snaps\n");
			G_Printf("---------------------------------------------------------------------\n");
		}
	}

	max_rate = trap_Cvar_VariableIntegerValue("sv_maxrate");

	for (i = 0; i < level.numConnectedClients; i++)
	{
		idnum  = level.sortedClients[i]; //level.sortedNames[i];
		cl     = &level.clients[idnum];
		cl_ent = g_entities + idnum;

		SanitizeString(cl->pers.netname, n2, qfalse);
		n2[26]   = 0;
		ref[0]   = 0;
		ready[0] = 0;

		// Rate info
		if (cl_ent->r.svFlags & SVF_BOT)
		{
			strcpy(rate, va("%s%s%s%s", "[BOT]", " -----", "       --", "     --"));
		}
		else if (cl->pers.connected == CON_CONNECTING)
		{
			strcpy(rate, va("%s", "^3>>> CONNECTING <<<^7"));
		}
		else
		{
			trap_GetUserinfo(idnum, userinfo, sizeof(userinfo));
			s          = Info_ValueForKey(userinfo, "rate");
			user_rate  = (max_rate > 0 && atoi(s) > max_rate) ? max_rate : atoi(s);
			s          = Info_ValueForKey(userinfo, "snaps");
			user_snaps = atoi(s);

			strcpy(rate, va("%5d%6d%9d%7d", cl->pers.clientTimeNudge, user_rate, cl->pers.clientMaxPackets, user_snaps));
		}

		if (g_gamestate.integer != GS_PLAYING)
		{
			if (cl->sess.sessionTeam == TEAM_SPECTATOR || cl->pers.connected == CON_CONNECTING)
			{
				strcpy(ready, ((ent) ? "^5--------^7 :" : "-------- :"));
			}
			else if (cl->pers.ready || (g_entities[idnum].r.svFlags & SVF_BOT))
			{
				strcpy(ready, ((ent) ? "^3(READY)^7  :" : "(READY)  :"));
			}
			else
			{
				strcpy(ready, ((ent) ? "^7NOTREADY^7 :" : "NOTREADY :"));
			}
		}

		if (cl->sess.referee)
		{
			strcpy(ref, "REF");
		}

		if (cl->sess.coach_team)
		{
			tteam = cl->sess.coach_team;
			coach = (ent) ? "^3C^7" : "C";
		}
		else
		{
			tteam = cl->sess.sessionTeam;
			coach = " ";
		}

		tc = (ent) ? "^7 " : " ";
		if (g_gametype.integer >= GT_WOLF)
		{
			if (tteam == TEAM_AXIS)
			{
				tc = (ent) ? "^1X^7" : "X";
			}
			if (tteam == TEAM_ALLIES)
			{
				tc = (ent) ? "^4L^7" : "L";
			}
		}

		if (ent)
		{
			CP(va("print \"%s%s%2d%s:%s %-26s^7%s  ^3%s^7\n\"", ready, tc, idnum, coach, ((ref[0]) ? "^3" : "^7"), n2, rate, ref));
		}
		else
		{
			G_Printf("%s%s%2d%s: %-26s%s  %s\n", ready, tc, idnum, coach, n2, rate, ref);
		}

		cnt++;
	}

	if (ent)
	{
		CP(va("print \"\n^3%2d^7 total players\n\n\"", cnt));
	}
	else
	{
		G_Printf("\n%2d total players\n\n", cnt);
	}

	// Team speclock info
	if (g_gametype.integer >= GT_WOLF)
	{
		for (i = TEAM_AXIS; i <= TEAM_ALLIES; i++)
		{
			if (teamInfo[i].spec_lock)
			{
				if (ent)
				{
					CP(va("print \"** %s team is speclocked.\n\"", aTeams[i]));
				}
				else
				{
					G_Printf("** %s team is speclocked.\n", aTeams[i]);
				}
			}
		}
	}
}
Ejemplo n.º 16
0
// forty - #607 - Merge in Density's damage received display code
// Prints current player match info.
//	--> FIXME: put the pretty print on the client
void G_printMatchInfo(gentity_t *ent)
{
	int i, j, cnt, eff;
	int tot_kills, tot_deaths, tot_gp, tot_sui, tot_tk, tot_dg, tot_dr, tot_tdg, tot_tdr;
	gclient_t *cl;
	char *ref;
	char n2[MAX_STRING_CHARS];


	cnt = 0;
	for(i=TEAM_AXIS; i<=TEAM_ALLIES; i++) {
		if(!TeamCount(-1, i)) continue;

		tot_kills = 0;
		tot_deaths = 0;
		tot_sui = 0;
		tot_tk = 0;
		tot_dg = 0;
		tot_dr = 0;
		tot_tdg = 0;
		tot_tdr = 0;
		tot_gp = 0;

		// Dens: Added TDR
		CP("sc \"\n^7TEAM   Player          Kll Dth Sui TK Eff  ^3GP^7    ^2DG    ^1DR  ^6TDG  ^4TDR  ^3Score\n"
			"^7--------------------------------------------------------------------------\n\"");

		for(j=0; j<level.numPlayingClients; j++) {
			cl = level.clients + level.sortedClients[j];

			if(cl->pers.connected != CON_CONNECTED || cl->sess.sessionTeam != i) continue;

			SanitizeString(cl->pers.netname, n2, qfalse);
			n2[15] = 0;

			ref = "^7";
			tot_kills += cl->sess.kills;
			tot_deaths += cl->sess.deaths;
			tot_sui += cl->sess.suicides;
			tot_tk += cl->sess.team_kills;
			tot_dg += cl->sess.damage_given;
			tot_dr += cl->sess.damage_received;
			tot_tdg += cl->sess.team_damage_given;
			tot_tdr += cl->sess.team_damage_received;
			tot_gp += cl->sess.game_points;

			eff = (cl->sess.deaths + cl->sess.kills == 0) ? 0 : 100 * cl->sess.kills / (cl->sess.deaths + cl->sess.kills);
			if(eff < 0) eff = 0;

			if(ent->client == cl ||
				(ent->client->sess.sessionTeam == TEAM_SPECTATOR &&
				ent->client->sess.spectatorState == SPECTATOR_FOLLOW &&
				ent->client->sess.spectatorClient == level.sortedClients[j])) {
					ref = "^3";
				}

				cnt++;
				CP(va("sc \"%-10s %s%-15s^3%4d%4d%4d%3d%s%4d^3%4d^2%6d^1%6d^6%5d^4%5d^3%7d\n\"",
					aTeams[i],
					ref,
					n2,
					cl->sess.kills,
					cl->sess.deaths,
					cl->sess.suicides,
					cl->sess.team_kills,
					ref,
					eff,
					cl->sess.game_points - (cl->sess.kills * WOLF_FRAG_BONUS),
					cl->sess.damage_given,
					cl->sess.damage_received,
					cl->sess.team_damage_given,
					cl->sess.team_damage_received,
					cl->ps.persistant[PERS_SCORE]));
		}

		eff = (tot_kills + tot_deaths == 0) ? 0 : 100 * tot_kills / (tot_kills + tot_deaths);
		if(eff < 0) eff = 0;

		CP(va("sc \"^7--------------------------------------------------------------------------\n"
			"%-10s ^5%-15s%4d%4d%4d%3d^5%4d^3%4d^2%6d^1%6d^6%5d^4%5d^3%7d\n\"",
			aTeams[i],
			"Totals",
			tot_kills,
			tot_deaths,
			tot_sui,
			tot_tk,
			eff,
			tot_gp - (tot_kills * WOLF_FRAG_BONUS),
			tot_dg,
			tot_dr,
			tot_tdg,
			tot_tdr,
			tot_gp));
	}

	CP(va("sc \"%s\n\n\" 0", ((!cnt) ? "^3\nNo scores to report." : "")));
	if (g_killRating.integer & KILL_RATING_VISIBLE) {
		//josh: reward messages for match and overall top killers
		G_TopKillersMessage(ent);
	}
	if (g_playerRating.integer & PLAYER_RATING_VISIBLE) {
		//josh: reward message for top player rating
		G_TopPlayerMessage(ent);
	}
}
Ejemplo n.º 17
0
const u8 *unref_sub_808286C(void)
{
    return SanitizeString(sTrainerVictorySpeech);
}
Ejemplo n.º 18
0
bool VerifyWallets()
{
    if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
        return true;
    }

    if (gArgs.IsArgSet("-walletdir")) {
        fs::path wallet_dir = gArgs.GetArg("-walletdir", "");
        if (!fs::exists(wallet_dir)) {
            return InitError(strprintf(_("Specified -walletdir \"%s\" does not exist"), wallet_dir.string()));
        } else if (!fs::is_directory(wallet_dir)) {
            return InitError(strprintf(_("Specified -walletdir \"%s\" is not a directory"), wallet_dir.string()));
        } else if (!wallet_dir.is_absolute()) {
            return InitError(strprintf(_("Specified -walletdir \"%s\" is a relative path"), wallet_dir.string()));
        }
    }

    LogPrintf("Using wallet directory %s\n", GetWalletDir().string());

    uiInterface.InitMessage(_("Verifying wallet(s)..."));

    // Keep track of each wallet absolute path to detect duplicates.
    std::set<fs::path> wallet_paths;

    for (const std::string& walletFile : gArgs.GetArgs("-wallet")) {
        if (boost::filesystem::path(walletFile).filename() != walletFile) {
            return InitError(strprintf(_("Error loading wallet %s. -wallet parameter must only specify a filename (not a path)."), walletFile));
        }

        if (SanitizeString(walletFile, SAFE_CHARS_FILENAME) != walletFile) {
            return InitError(strprintf(_("Error loading wallet %s. Invalid characters in -wallet filename."), walletFile));
        }

        fs::path wallet_path = fs::absolute(walletFile, GetWalletDir());

        if (fs::exists(wallet_path) && (!fs::is_regular_file(wallet_path) || fs::is_symlink(wallet_path))) {
            return InitError(strprintf(_("Error loading wallet %s. -wallet filename must be a regular file."), walletFile));
        }

        if (!wallet_paths.insert(wallet_path).second) {
            return InitError(strprintf(_("Error loading wallet %s. Duplicate -wallet filename specified."), walletFile));
        }

        std::string strError;
        if (!CWalletDB::VerifyEnvironment(walletFile, GetWalletDir().string(), strError)) {
            return InitError(strError);
        }

        if (gArgs.GetBoolArg("-salvagewallet", false)) {
            // Recover readable keypairs:
            CWallet dummyWallet;
            std::string backup_filename;
            if (!CWalletDB::Recover(walletFile, (void *)&dummyWallet, CWalletDB::RecoverKeysOnlyFilter, backup_filename)) {
                return false;
            }
        }

        std::string strWarning;
        bool dbV = CWalletDB::VerifyDatabaseFile(walletFile, GetWalletDir().string(), strWarning, strError);
        if (!strWarning.empty()) {
            InitWarning(strWarning);
        }
        if (!dbV) {
            InitError(strError);
            return false;
        }
    }

    return true;
}
Ejemplo n.º 19
0
// Prints current player match info.
//  --> FIXME: put the pretty print on the client
void G_printMatchInfo(gentity_t *ent)
{
	int       i, j, cnt = 0, eff, time_eff;
	int       tot_timex, tot_timel, tot_timep, tot_kills, tot_deaths, tot_gibs, tot_sk, tot_tk, tot_tg, tot_dg, tot_dr, tot_tdg, tot_tdr, tot_xp;
#ifdef FEATURE_RATING
	float     tot_rating, tot_delta;
#endif
	gclient_t *cl;
	char      *ref;
	char      n2[MAX_STRING_CHARS];

	for (i = TEAM_AXIS; i <= TEAM_SPECTATOR; i++)
	{
		if (!TeamCount(-1, i))
		{
			continue;
		}

		tot_timex  = 0;
		tot_timel  = 0;
		tot_timep  = 0;
		tot_kills  = 0;
		tot_deaths = 0;
		tot_gibs   = 0;
		tot_sk     = 0;
		tot_tk     = 0;
		tot_tg     = 0;
		tot_dg     = 0;
		tot_dr     = 0;
		tot_tdg    = 0;
		tot_tdr    = 0;
		tot_xp     = 0;
#ifdef FEATURE_RATING
		tot_rating = 0.f;
		tot_delta  = 0.f;
#endif

		CP("sc \"\n\"");
#ifdef FEATURE_RATING
		CP("sc \"^7TEAM       Player         ^1 TmX^4 TmL^7 TmP^7 Kll Dth Gib  SK  TK  TG^7 Eff^2    DG^1    DR^6  TDG^4  TDR^3  Score^8  Rating^5  Delta\n\"");
		CP("sc \"^7--------------------------------------------------------------------------------------------------------------\n\"");
#else
		CP("sc \"^7TEAM       Player         ^1 TmX^4 TmL^7 TmP^7 Kll Dth Gib  SK  TK  TG^7 Eff^2    DG^1    DR^6  TDG^4  TDR^3  Score\n\"");
		CP("sc \"^7-----------------------------------------------------------------------------------------------\n\"");

#endif

		for (j = 0; j < level.numConnectedClients; j++)
		{
			cl = level.clients + level.sortedClients[j];

			if (cl->pers.connected != CON_CONNECTED || cl->sess.sessionTeam != i)
			{
				continue;
			}

			SanitizeString(cl->pers.netname, n2, qfalse);
			n2[15] = 0;

			ref         = "^7";
			tot_timex  += cl->sess.time_axis;
			tot_timel  += cl->sess.time_allies;
			tot_timep  += cl->sess.time_played;
			tot_kills  += cl->sess.kills;
			tot_deaths += cl->sess.deaths;
			tot_gibs   += cl->sess.gibs;
			tot_sk     += cl->sess.self_kills;
			tot_tk     += cl->sess.team_kills;
			tot_tg     += cl->sess.team_gibs;
			tot_dg     += cl->sess.damage_given;
			tot_dr     += cl->sess.damage_received;
			tot_tdg    += cl->sess.team_damage_given;
			tot_tdr    += cl->sess.team_damage_received;
			tot_xp     += cl->ps.persistant[PERS_SCORE];
#ifdef FEATURE_RATING
			tot_rating += cl->sess.mu - 3 * cl->sess.sigma;
			tot_delta  += (cl->sess.mu - 3 * cl->sess.sigma) - (cl->sess.oldmu - 3 * cl->sess.oldsigma);
#endif

			eff = (cl->sess.deaths + cl->sess.kills == 0) ? 0 : 100 * cl->sess.kills / (cl->sess.deaths + cl->sess.kills);
			if (eff < 0)
			{
				eff = 0;
			}

			time_eff = (cl->sess.time_axis + cl->sess.time_allies == 0) ? 0 : 100 * cl->sess.time_played / (cl->sess.time_axis + cl->sess.time_allies);

			if (ent->client == cl ||
			    (ent->client->sess.sessionTeam == TEAM_SPECTATOR &&
			     ent->client->sess.spectatorState == SPECTATOR_FOLLOW &&
			     ent->client->sess.spectatorClient == level.sortedClients[j]))
			{
				ref = "^3";
			}

			cnt++;
#ifdef FEATURE_RATING
			trap_SendServerCommand(ent - g_entities, va("sc \"%-14s %s%-15s^1%4d^4%4d^7%s%4d^3%4d%4d%4d%4d%4d%4d%s%4d^2%6d^1%6d^6%5d^4%5d^3%7d^8%8.2f^5%+7.2f\n\"",
#else
			trap_SendServerCommand(ent - g_entities, va("sc \"%-14s %s%-15s^1%4d^4%4d^7%s%4d^3%4d%4d%4d%4d%4d%4d%s%4d^2%6d^1%6d^6%5d^4%5d^3%7d\n\"",
#endif
			      aTeams[i],
			      ref,
			      n2,
			      cl->sess.time_axis / 60000,
			      cl->sess.time_allies / 60000,
			      ref,
			      time_eff,
			      cl->sess.kills,
			      cl->sess.deaths,
			      cl->sess.gibs,
			      cl->sess.self_kills,
			      cl->sess.team_kills,
			      cl->sess.team_gibs,
			      ref,
			      eff,
			      cl->sess.damage_given,
			      cl->sess.damage_received,
			      cl->sess.team_damage_given,
			      cl->sess.team_damage_received,
			      cl->ps.persistant[PERS_SCORE]
#ifdef FEATURE_RATING
			      ,
			      (cl->sess.mu - 3 * cl->sess.sigma < 0.f) ? 0.f : cl->sess.mu - 3 * cl->sess.sigma,
			      (cl->sess.mu - 3 * cl->sess.sigma) - (cl->sess.oldmu - 3 * cl->sess.oldsigma)
#endif
			      ));
		}

		eff = (tot_kills + tot_deaths == 0) ? 0 : 100 * tot_kills / (tot_kills + tot_deaths);
		if (eff < 0)
		{
			eff = 0;
		}

		time_eff = (tot_timex + tot_timel == 0) ? 0 : 100 * tot_timep / (tot_timex + tot_timel);

#ifdef FEATURE_RATING
		CP("sc \"^7--------------------------------------------------------------------------------------------------------------\n\"");
		trap_SendServerCommand(ent - g_entities, va("sc \"%-14s ^5%-15s^1%4d^4%4d^5%4d%4d%4d%4d%4d%4d%4d^5%4d^2%6d^1%6d^6%5d^4%5d^3%7d^8%8.2f^5%+7.2f\n\"",
#else
		CP("sc \"^7-----------------------------------------------------------------------------------------------\n\"");
		trap_SendServerCommand(ent - g_entities, va("sc \"%-14s ^5%-15s^1%4d^4%4d^5%4d%4d%4d%4d%4d%4d%4d^5%4d^2%6d^1%6d^6%5d^4%5d^3%7d\n\"",
#endif
		      aTeams[i],
		      "Totals",
		      tot_timex / 60000,
		      tot_timel / 60000,
		      time_eff,
		      tot_kills,
		      tot_deaths,
		      tot_gibs,
		      tot_sk,
		      tot_tk,
		      tot_tg,
		      eff,
		      tot_dg,
		      tot_dr,
		      tot_tdg,
		      tot_tdr,
		      tot_xp
#ifdef FEATURE_RATING
		      ,
		      (tot_rating < 0.f) ? 0.f : tot_rating / TeamCount(-1, i),
		      tot_delta / TeamCount(-1, i)
#endif
		      ));
	}

	CP(va("sc \"%s\n\n\" 0", ((!cnt) ? "^3\nNo scores to report." : "")));
}
Ejemplo n.º 20
0
/** HTTP request callback */
static void http_request_cb(struct evhttp_request* req, void* arg)
{
    // Disable reading to work around a libevent bug, fixed in 2.2.0.
    if (event_get_version_number() >= 0x02010600 && event_get_version_number() < 0x02020001) {
        evhttp_connection* conn = evhttp_request_get_connection(req);
        if (conn) {
            bufferevent* bev = evhttp_connection_get_bufferevent(conn);
            if (bev) {
                bufferevent_disable(bev, EV_READ);
            }
        }
    }
    std::unique_ptr<HTTPRequest> hreq(new HTTPRequest(req));

    // Early address-based allow check
    if (!ClientAllowed(hreq->GetPeer())) {
        LogPrint(BCLog::HTTP, "HTTP request from %s rejected: Client network is not allowed RPC access\n",
                 hreq->GetPeer().ToString());
        hreq->WriteReply(HTTP_FORBIDDEN);
        return;
    }

    // Early reject unknown HTTP methods
    if (hreq->GetRequestMethod() == HTTPRequest::UNKNOWN) {
        LogPrint(BCLog::HTTP, "HTTP request from %s rejected: Unknown HTTP request method\n",
                 hreq->GetPeer().ToString());
        hreq->WriteReply(HTTP_BADMETHOD);
        return;
    }

    LogPrint(BCLog::HTTP, "Received a %s request for %s from %s\n",
             RequestMethodString(hreq->GetRequestMethod()), SanitizeString(hreq->GetURI(), SAFE_CHARS_URI).substr(0, 100), hreq->GetPeer().ToString());

    // Find registered handler for prefix
    std::string strURI = hreq->GetURI();
    std::string path;
    std::vector<HTTPPathHandler>::const_iterator i = pathHandlers.begin();
    std::vector<HTTPPathHandler>::const_iterator iend = pathHandlers.end();
    for (; i != iend; ++i) {
        bool match = false;
        if (i->exactMatch)
            match = (strURI == i->prefix);
        else
            match = (strURI.substr(0, i->prefix.size()) == i->prefix);
        if (match) {
            path = strURI.substr(i->prefix.size());
            break;
        }
    }

    // Dispatch to worker thread
    if (i != iend) {
        std::unique_ptr<HTTPWorkItem> item(new HTTPWorkItem(std::move(hreq), path, i->handler));
        assert(workQueue);
        if (workQueue->Enqueue(item.get()))
            item.release(); /* if true, queue took ownership */
        else {
            LogPrintf("WARNING: request rejected because http work queue depth exceeded, it can be increased with the -rpcworkqueue= setting\n");
            item->req->WriteReply(HTTP_INTERNAL, "Work queue depth exceeded");
        }
    } else {
        hreq->WriteReply(HTTP_NOTFOUND);
    }
}