Exemple #1
0
	bool InterceptClientMessage(CClientConnection* Client, int argc, const char** argv) {
		g_Ret = true;

		CUser* User = Client->GetOwner();

		CallBinds(Type_PreScript, NULL, NULL, 0, NULL);

		g_CurrentClient = Client;
		CallBinds(Type_Client, User ? User->GetUsername() : "", Client, argc, argv);
		CallBinds(Type_PostScript, NULL, NULL, 0, NULL);

		return g_Ret;
	}
void CServerContext::HandleCallbackClientApprove( GSClientApprove_t *pClientApprove )
{
	std::cout << "[SERVER] Back-end approved " << pClientApprove->m_SteamID << std::endl;

	SteamUserMap::iterator iter = clientSteamMap.find( pClientApprove->m_SteamID );
	if( iter != clientSteamMap.end() )
	{
		CUser *user = iter->second;
		std::cout << "[SERVER] User " << *user << " was authed, updating user data." << std::endl;
		gameserver->UpdateUserData(user->GetSteamID(), user->GetUsername().c_str(), 0);

		gameserveritems->LoadItems(user->GetSteamID());
	}
}
Exemple #3
0
    bool Block(const CString& sUser) {
        CUser* pUser = CZNC::Get().FindUser(sUser);

        if (!pUser) return false;

        // Disconnect all clients
        vector<CClient*> vpClients = pUser->GetAllClients();
        vector<CClient*>::iterator it;
        for (it = vpClients.begin(); it != vpClients.end(); ++it) {
            (*it)->PutStatusNotice(MESSAGE);
            (*it)->Close(Csock::CLT_AFTERWRITE);
        }

        // Disconnect all networks from irc
        vector<CIRCNetwork*> vNetworks = pUser->GetNetworks();
        for (vector<CIRCNetwork*>::iterator it2 = vNetworks.begin();
             it2 != vNetworks.end(); ++it2) {
            (*it2)->SetIRCConnectEnabled(false);
        }

        SetNV(pUser->GetUsername(), "");
        return true;
    }
bool CNewUserDetailsPageBuilder::Build(CWholePage* pWholePage)
{
    // pointer to the xml objects we are going to need
    CUser*			pViewer = NULL;
    // get or create all the appropriate xml objects
    // first get the current user object and test that it isn't NULL
    pViewer = m_InputContext.GetCurrentUser();

    TDVASSERT(pViewer != NULL, "CNewUserDetailsPageBuilder::Build() called with NULL current user");

    CTDVString sPageError;
    bool bSuccess = true;
    bool bUpdateWasValid = true; // make a boolean variable to assess the validity of the submission

    // If the person is unregistered, show/deal with new password request
    // Also do this if 'unregcmd' exists as a parameter, so a
    // registered person can still request a new password.
    bool bRequest = false;
    CTDVString sRequestFormCommand = NULL;
    if (m_InputContext.GetParamString("unregcmd", sRequestFormCommand))
    {
        bRequest = true;
    }
    if (bRequest || pViewer == NULL)
    {
        CTDVString sMessage;
        CTDVString sMessageType = "";
        bool bSubmission = false;
        CTDVString sUpdateError = NULL;
        if (bSuccess && bRequest)
        {
            if (sRequestFormCommand.CompareText("Submit"))
            {
                bSubmission = true;
            }
        }
        if (bSuccess && bSubmission)
        {
            CTDVString sEmail;
            CTDVString sLoginname;
            CTDVString sUserid;
            bUpdateWasValid = bUpdateWasValid && m_InputContext.GetParamString("email", sEmail);
            bUpdateWasValid = bUpdateWasValid && m_InputContext.GetParamString("loginname", sLoginname);
            bUpdateWasValid = bUpdateWasValid && m_InputContext.GetParamString("userid", sUserid);

            while (sUserid.GetLength() > 0 && (sUserid[0] == 'u' || sUserid[0] == 'U' || sUserid[0] == ' '))
            {
                sUserid.RemoveLeftChars(1);
            }
            /*
               if loginname is empty, fall back on userid
            */
            if (bUpdateWasValid && sLoginname.IsEmpty())
            {
                CUser TempUser(m_InputContext);
                if (TempUser.CreateFromID(atoi(sUserid)))
                {
                    bUpdateWasValid = TempUser.GetLoginName(sLoginname);
                }
                else
                {
                    bUpdateWasValid = false;
                }
            }
            if (bUpdateWasValid)
            {
                CRegisterObject RegObj(m_InputContext);
                bUpdateWasValid = RegObj.RequestPassword(sLoginname, sEmail);
                if (bUpdateWasValid)
                {
                    sMessage = "A new password has been set and is being sent to you via email.";
                    sMessageType = "newpasswordsent";
                }
                else
                {
                    sMessage = "The username or nickname you entered was not valid, or did not match the email address you provided.";
                    sMessageType = "newpasswordfailed";
                }
            }
        }

        bSuccess = InitPage(pWholePage, "USERDETAILS",true,false);

        if (pViewer != NULL)
        {
            pViewer->SetIDNameVisible();
            pViewer->SetIDNameEmailVisible();
            pWholePage->AddInside("VIEWING-USER", pViewer);
        }

        CTDVString formXML;
        formXML << "<USER-DETAILS-UNREG>";
        formXML << "<MESSAGE TYPE='" << sMessageType << "'>" << sMessage << "</MESSAGE>";
        formXML << "</USER-DETAILS-UNREG>";

        bSuccess = pWholePage->AddInside("H2G2", formXML);
    }
    else
        // We are registered, handle userdetails form
    {
        // before anything else find out whether we are dealing with a request to view
        // the page or a submit request to update the details
        bool bSubmission = false;
        CTDVString sFormCommand = NULL;
        CTDVString sUpdateError;
        CTDVString sUpdateType;
        if (m_InputContext.ParamExists("setskin"))
        {
            CTDVString sNewSkin;
            if(m_InputContext.GetParamString("NewSkin", sNewSkin))
            {
                pViewer->SetPrefSkin(sNewSkin);
                bSuccess = pViewer->UpdateDetails();
                bSuccess = bSuccess && m_InputContext.SetSkin(sNewSkin);
                if (bSuccess)
                {
                    sUpdateError = "Your new skin has been set";
                    sUpdateType = "skinset";
                }
            }
        }

        // if a submit request then it will have a CGI parameter called 'cmd'
        // with the value 'submit'
        if (bSuccess)
        {
            if (m_InputContext.GetParamString("cmd", sFormCommand))
            {
                if (sFormCommand.CompareText("Submit"))
                {
                    bSubmission = true;
                }
            }
        }

        if ((pViewer != NULL) && pViewer->GetIsBannedFromPosting())
        {
            bUpdateWasValid = false;
            sUpdateError = "Not allowed";
            sUpdateType = "restricteduser";
        }

        if ( bUpdateWasValid && bSubmission && bUpdateWasValid )
        {
            bUpdateWasValid  = UpdateUserDetails(pViewer, sUpdateError, sUpdateType);
        }

        bSuccess = bSuccess && InitPage(pWholePage, "USERDETAILS",true);

        // now add the XML for the FORM and its contents
        int iUserID = pViewer->GetUserID();

        CTDVString sUsername;
        //	CTDVString sFirstNames;
        //	CTDVString sLastName;
        CTDVString sEmail;
        CTDVString sPrefSkin;
        int iPrefUserMode;
        int iPrefForumStyle;
        CTDVString sPrefXML;
        CTDVString sSiteSuffix;
        CTDVString sRegion;
        // get the users settings, which may have just been updated...
        bSuccess = bSuccess && pViewer->GetUsername(sUsername);
        //		bSuccess = bSuccess && pViewer->GetFirstNames(sFirstNames);
        //		bSuccess = bSuccess && pViewer->GetLastName(sLastName);
        bSuccess = bSuccess && pViewer->GetEmail(sEmail);
        bSuccess = bSuccess && pViewer->GetPrefSkin(&sPrefSkin);
        bSuccess = bSuccess && pViewer->GetPrefUserMode(&iPrefUserMode);
        bSuccess = bSuccess && pViewer->GetPrefForumStyle(&iPrefForumStyle);
        bSuccess = bSuccess && pViewer->GetPrefXML(&sPrefXML);
        bSuccess = bSuccess && pViewer->GetSiteSuffix(sSiteSuffix);
        bSuccess = bSuccess && pViewer->GetRegion(sRegion);

        // construct the XML for the FORM and then insert it inside the body of the page
        if (bSuccess)
        {
            // TODO: is this the only XML we need to output?
            CTDVString sMessage;
            CTDVString sMessageType = "";

            if (sUpdateError.IsEmpty() && bSubmission)
            {
                sMessage = "Your details have been updated";
                sMessageType="detailsupdated";

            }
            else
            {
                sMessage = sUpdateError;
                sMessageType = sUpdateType;
            }

            // escape all XML sequences in the name fields before showing them in the form
            CXMLObject::EscapeAllXML(&sUsername);
            //		CXMLObject::EscapeAllXML(&sFirstNames);
            //		CXMLObject::EscapeAllXML(&sLastName);

            // now build the XML representation of the form for editing user details
            CTDVString formXML;
            formXML << "<USER-DETAILS-FORM>";
            formXML << "<MESSAGE TYPE='" << sMessageType << "'>" << sMessage << "</MESSAGE>";
            formXML << "<USERID>" << iUserID << "</USERID>";
            formXML << "<USERNAME>" << sUsername << "</USERNAME>";
            //		formXML << "<FIRST-NAMES>" << sFirstNames << "</FIRST-NAMES>";
            //		formXML << "<LAST-NAME>" << sLastName << "</LAST-NAME>";
            formXML << "<EMAIL-ADDRESS>" << sEmail << "</EMAIL-ADDRESS>";
            formXML << "<REGION>" << sRegion << "</REGION>";
            formXML << "<PREFERENCES>"
                    << "<SKIN>" << sPrefSkin << "</SKIN>"
                    << "<USER-MODE>" << iPrefUserMode << "</USER-MODE>"
                    << "<FORUM-STYLE>" << iPrefForumStyle << "</FORUM-STYLE>"
                    << "<SITESUFFIX>" << sSiteSuffix << "</SITESUFFIX>"
                    << "</PREFERENCES>";
            formXML << "<SITEPREFERENCES>" << sPrefXML << "</SITEPREFERENCES>";
            formXML << "</USER-DETAILS-FORM>";

            bSuccess = pWholePage->AddInside("H2G2", formXML);

            //Insert Regions XML into page if they exist.
            CTDVString delimit = m_InputContext.GetCurrentSiteOptionString("KeyPhrases","DelimiterToken");
            CThreadSearchPhrase tsp(m_InputContext,delimit);
            if ( bSuccess && tsp.GetSiteKeyPhrasesXML() )
            {
                pWholePage->AddInside("H2G2","<THREADSEARCHPHRASE/>");
                pWholePage->AddInside("H2G2/THREADSEARCHPHRASE",&tsp);
            }
        }
    }  /* end of 'we are registered user' if */

    if (!bSuccess && pWholePage != NULL)
    {
        // if haven't been able to produce a page then create a simple error page
        CTDVString sPageXML = "<ARTICLE>";
        sPageXML << "<SUBJECT>Error Page</SUBJECT>";
        sPageXML << "<GUIDE><BODY>";
        if (sPageError.IsEmpty())
        {
            sPageXML << "User Details Page could not be displayed due to unspecified strangeness";
        }
        else
        {
            sPageXML << "User Details Page could not be displayed: " << sPageError;
        }
        sPageXML << "</BODY></GUIDE></ARTICLE>";
        bSuccess = InitPage(pWholePage, "ERRORPAGE",true,false);
        bSuccess = bSuccess && pWholePage->AddInside("H2G2", sPageXML);
    }
    return bSuccess;
}
Exemple #5
0
	bool InterceptClientCommand(CClientConnection* Client, const char* Subcommand, int argc, const char** argv, bool NoticeUser) {
		CUser* User = Client->GetOwner();

		g_NoticeUser = NoticeUser;

		g_CurrentClient = Client;

		g_Ret = true;

		CallBinds(Type_Command, Client->GetOwner()->GetUsername(), Client, argc, argv);

		if (g_Ret && strcasecmp(Subcommand, "help") == 0 && User && User->IsAdmin()) {
			commandlist_t *Commands = Client->GetCommandList();

			AddCommand(Commands, "tcl", "Admin", "executes tcl commands", "Syntax: "
				"tcl command\nExecutes the specified tcl command.");

			g_Ret = false;
		}

		if (g_Ret && strcasecmp(Subcommand, "tcl") == 0 && User && User->IsAdmin()) {
			if (argc <= 1) {
				if (NoticeUser)
					Client->RealNotice("Syntax: tcl :command");
				else
					Client->Privmsg("Syntax: tcl :command");

				return true;
			}

			setctx(User->GetUsername());

			Tcl_DString dsScript;
			const char **argvdup;

			argvdup = ArgDupArray(argv);
			ArgRejoinArray(argvdup, 1);

			g_CurrentClient = Client;

			int Code = Tcl_EvalEx(g_Interp, Tcl_UtfToExternalDString(g_Encoding, argvdup[1], -1, &dsScript),
				-1, TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);

			ArgFreeArray(argvdup);

			Tcl_DStringFree(&dsScript);

			Tcl_Obj* Result = Tcl_GetObjResult(g_Interp);

			const char* strResult = Tcl_GetString(Result);

			if (Code == TCL_ERROR) {
				if (NoticeUser)
					Client->RealNotice("An error occured in the tcl script:");
				else
					Client->Privmsg("An error occured in the tcl script:");
			}

			if (strResult && *strResult) {
				Tcl_DString dsResult;

				char* Dup = strdup(Tcl_UtfToExternalDString(g_Encoding, strResult, -1, &dsResult));

				Tcl_DStringFree(&dsResult);

				char* token = strtok(Dup, "\n");

				while (token != NULL) {
					if (NoticeUser)
						Client->RealNotice(*token ? token : "empty string.");
					else
						Client->Privmsg(*token ? token : "empty string.");

					token = strtok(NULL, "\n");
				}

				free(Dup);
			} else {
					if (NoticeUser)
						Client->RealNotice("<no error>");
					else
						Client->Privmsg("<no error>");
			}

			g_Ret = false;
		}

		return !g_Ret;
	}