Raised This Month: $51 Target: $400
 12% 

[CSGO] IsCookieTrue !!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dr.Mohammad
Senior Member
Join Date: Jan 2016
Location: CSGO Servers
Old 04-01-2019 , 23:45   [CSGO] IsCookieTrue !!
Reply With Quote #1

hi guys!!

i set cookie "0" or "1" before, i want check cookie for return true or false!!
this is true??
PHP Code:
stock bool IsCookieTrue(Handle CookieName)
{
    
char Char_Value[8];
    
GetClientCookie(clientCookieNameChar_Valuesizeof(Char_Value));
    
int Int_Value StringToInt(Char_Value);
    
    if(
Int_Value == 1)
    {
        return 
true;
    }
    else if(
Int_Value <= || Int_Value 1)
    {
        return 
false;
    }

edit: How i can save cookie only for server??
PHP Code:
SetServerCookie(CookieNameChar_Value);
GetServerCookie(CookieNameChar_Valuesizeof(Char_Value)); 

Last edited by Dr.Mohammad; 04-02-2019 at 00:03.
Dr.Mohammad is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 04-02-2019 , 01:31   Re: [CSGO] IsCookieTrue !!
Reply With Quote #2

Quote:
Originally Posted by Dr.Mohammad View Post
hi guys!!

i set cookie "0" or "1" before, i want check cookie for return true or false!!
this is true??
PHP Code:
stock bool IsCookieTrue(Handle CookieName)
{
    
char Char_Value[8];
    
GetClientCookie(clientCookieNameChar_Valuesizeof(Char_Value));
    
int Int_Value StringToInt(Char_Value);
    
    if(
Int_Value == 1)
    {
        return 
true;
    }
    else if(
Int_Value <= || Int_Value 1)
    {
        return 
false;
    }

edit: How i can save cookie only for server??
PHP Code:
SetServerCookie(CookieNameChar_Value);
GetServerCookie(CookieNameChar_Valuesizeof(Char_Value)); 
Just save a file in data/yourplugin.txt and switch it when needed
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
Dr.Mohammad
Senior Member
Join Date: Jan 2016
Location: CSGO Servers
Old 04-02-2019 , 06:26   Re: [CSGO] IsCookieTrue !!
Reply With Quote #3

Quote:
Originally Posted by eyal282 View Post
Just save a file in data/yourplugin.txt and switch it when needed
can you help me more??
Dr.Mohammad is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 04-02-2019 , 08:34   Re: [CSGO] IsCookieTrue !!
Reply With Quote #4

I'm not done with these functions and they aren't working properly. I didn't use any syntax highlighting or anything so it might look terrible. I'll fix this NON WORKING CODE later, but the only issue I can see right now is the fact that overwriting a value doesn't do anything at all.

Code:
#include <sourcemod>

new const String:ServerValuesPath[] = "data/ServerValues.txt"

public OnPluginStart()
{
	StoreServerValue("test", "thr", false);
	new bool:tr1 = StoreServerValue("bruh", "moment", false);
	StoreServerValue("tester", "hgr", false);
	new bool:tr2 = StoreServerValue("bruh", "momentnum2", true);
	new bool:fls1 = StoreServerValue("bruh", "mome", false);
	
	new String:Buffer[128];
	ReadServerValue("bruh", Buffer, sizeof(Buffer));
	
	LogAction(-1, -1, "%i %i %i - [momentnum2] %s", tr1, tr2, fls1, Buffer);
}

// returns true if successfully stored, false if value already exists.
stock bool:StoreServerValue(const String:Key[], const String:Value[], bool:replace=true)
{
	LogAction(-1, -1, "nnn");
	new String:FilePath[PLATFORM_MAX_PATH];
	
	BuildPath(Path_SM, FilePath, sizeof(FilePath), ServerValuesPath);
	
	if(!FileExists(FilePath))
		CreateEmptyFile(FilePath);
	
	//RemoveLines(FilePath);
	
	new Handle:hFile = OpenFile(FilePath, "r+");
	
	new String:LineBuffer[256], String:KeyBuffer[128];
	while(!IsEndOfFile(hFile))
	{
		ReadFileLine(hFile, LineBuffer, sizeof(LineBuffer));
		
		BreakString(LineBuffer, KeyBuffer, sizeof(KeyBuffer));
		
		if(StrEqual(Key, KeyBuffer, true))
		{
			if(!replace)
			{
				LogAction(-1, -1, "a");
				CloseHandle(hFile);
				return false;
			}
			
			LogAction(-1, -1, "b");
			// We don't need LineBuffer anymore, we can use it to replace the data.
			Format(LineBuffer, sizeof(LineBuffer), "\"%s\" \"%s\"", Key, Value);
			WriteFileLine(hFile, LineBuffer);
			
			CloseHandle(hFile);
			return true;
		}
	}

	LogAction(-1, -1, "c");
	Format(LineBuffer, sizeof(LineBuffer), "\"%s\" \"%s\"", Key, Value);
	WriteFileLine(hFile, LineBuffer);	
	
	CloseHandle(hFile);
	
	return true;
}

// Removes lines that aren't in two arguments ( "key" "value" ) and empty lines.

// returns amount of lines deleted.
stock RemoveLines(const String:Path[])
{
	new count = 0;
	
	new Handle:hFile = OpenFile(Path, "r");
	
	new String:TempFilePath[PLATFORM_MAX_PATH];
	Format(TempFilePath, sizeof(TempFilePath), Path);
	
	new pathlen = strlen(TempFilePath);
	
	while(TempFilePath[pathlen] != '/' && TempFilePath[pathlen] != '\\')
		pathlen--;
	
	TempFilePath[pathlen+1] = EOS;
	Format(TempFilePath, sizeof(TempFilePath), "%slineremoval_temp.txt", TempFilePath);
	
	// If it's called temp, I'm legally allowed to delete it :D
	DeleteFile(TempFilePath);
	
	new Handle:hTempFile = OpenFile(TempFilePath, "a+");
	
	new String:LineBuffer[256];
	while(!IsEndOfFile(hFile))
	{
		ReadFileLine(hFile, LineBuffer, sizeof(LineBuffer));
		
		if(LineBuffer[0] == EOS)
		{
			count++;
			continue;
		}	
		else if(GetStringArgumentCount(LineBuffer, sizeof(LineBuffer)) != 2)
		{
			count++;
			continue;
		}	
		
		WriteFileLine(hTempFile, LineBuffer);
	}
	
	CloseHandle(hFile);
	CloseHandle(hTempFile);
	DeleteFile(Path);
	RenameFile(Path, TempFilePath);
	
	return count;
}

stock GetStringArgumentCount(const String:source[], length)
{
	new String:dummy_str[length];
	new count = 0, arglen;
	
	while((arglen = BreakString(source[arglen], dummy_str, length)) != -1)
		count++;
		
	if(count > 0)
		count++; // It always rushes one count ahead as it gives index to next argument, if a string has two arguments, only one arglen will be taken in a loop.
		
	return count;
}

// returns true if found, false otherwise.

stock bool:ReadServerValue(const String:Key[], String:buffer[], bufferlen)
{
	new String:FilePath[PLATFORM_MAX_PATH];
	
	BuildPath(Path_SM, FilePath, sizeof(FilePath), ServerValuesPath);
	
	if(!FileExists(FilePath))
		return false;
	
	new Handle:hFile = OpenFile(FilePath, "r");
	
	if(hFile == INVALID_HANDLE)
		return false;
	
	new String:LineBuffer[256], len, String:KeyBuffer[128];
	while(!IsEndOfFile(hFile))
	{
		ReadFileLine(hFile, LineBuffer, sizeof(LineBuffer));
		
		len = BreakString(LineBuffer, KeyBuffer, sizeof(KeyBuffer));
		
		if(StrEqual(Key, KeyBuffer))
		{
			BreakString(LineBuffer[len], buffer, bufferlen);
			
			CloseHandle(hFile);
			return true;
		}
	}

	CloseHandle(hFile);
	return false;
}

stock CreateEmptyFile(const String:Path[])
{
	CloseHandle(OpenFile(Path, "a"));
}
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
Dr.Mohammad
Senior Member
Join Date: Jan 2016
Location: CSGO Servers
Old 04-02-2019 , 09:10   Re: [CSGO] IsCookieTrue !!
Reply With Quote #5

Quote:
Originally Posted by eyal282 View Post
I'm not done with these functions and they aren't working properly. I didn't use any syntax highlighting or anything so it might look terrible. I'll fix this NON WORKING CODE later, but the only issue I can see right now is the fact that overwriting a value doesn't do anything at all.

Code:
#include <sourcemod>

new const String:ServerValuesPath[] = "data/ServerValues.txt"

public OnPluginStart()
{
	StoreServerValue("test", "thr", false);
	new bool:tr1 = StoreServerValue("bruh", "moment", false);
	StoreServerValue("tester", "hgr", false);
	new bool:tr2 = StoreServerValue("bruh", "momentnum2", true);
	new bool:fls1 = StoreServerValue("bruh", "mome", false);
	
	new String:Buffer[128];
	ReadServerValue("bruh", Buffer, sizeof(Buffer));
	
	LogAction(-1, -1, "%i %i %i - [momentnum2] %s", tr1, tr2, fls1, Buffer);
}

// returns true if successfully stored, false if value already exists.
stock bool:StoreServerValue(const String:Key[], const String:Value[], bool:replace=true)
{
	LogAction(-1, -1, "nnn");
	new String:FilePath[PLATFORM_MAX_PATH];
	
	BuildPath(Path_SM, FilePath, sizeof(FilePath), ServerValuesPath);
	
	if(!FileExists(FilePath))
		CreateEmptyFile(FilePath);
	
	//RemoveLines(FilePath);
	
	new Handle:hFile = OpenFile(FilePath, "r+");
	
	new String:LineBuffer[256], String:KeyBuffer[128];
	while(!IsEndOfFile(hFile))
	{
		ReadFileLine(hFile, LineBuffer, sizeof(LineBuffer));
		
		BreakString(LineBuffer, KeyBuffer, sizeof(KeyBuffer));
		
		if(StrEqual(Key, KeyBuffer, true))
		{
			if(!replace)
			{
				LogAction(-1, -1, "a");
				CloseHandle(hFile);
				return false;
			}
			
			LogAction(-1, -1, "b");
			// We don't need LineBuffer anymore, we can use it to replace the data.
			Format(LineBuffer, sizeof(LineBuffer), "\"%s\" \"%s\"", Key, Value);
			WriteFileLine(hFile, LineBuffer);
			
			CloseHandle(hFile);
			return true;
		}
	}

	LogAction(-1, -1, "c");
	Format(LineBuffer, sizeof(LineBuffer), "\"%s\" \"%s\"", Key, Value);
	WriteFileLine(hFile, LineBuffer);	
	
	CloseHandle(hFile);
	
	return true;
}

// Removes lines that aren't in two arguments ( "key" "value" ) and empty lines.

// returns amount of lines deleted.
stock RemoveLines(const String:Path[])
{
	new count = 0;
	
	new Handle:hFile = OpenFile(Path, "r");
	
	new String:TempFilePath[PLATFORM_MAX_PATH];
	Format(TempFilePath, sizeof(TempFilePath), Path);
	
	new pathlen = strlen(TempFilePath);
	
	while(TempFilePath[pathlen] != '/' && TempFilePath[pathlen] != '\\')
		pathlen--;
	
	TempFilePath[pathlen+1] = EOS;
	Format(TempFilePath, sizeof(TempFilePath), "%slineremoval_temp.txt", TempFilePath);
	
	// If it's called temp, I'm legally allowed to delete it :D
	DeleteFile(TempFilePath);
	
	new Handle:hTempFile = OpenFile(TempFilePath, "a+");
	
	new String:LineBuffer[256];
	while(!IsEndOfFile(hFile))
	{
		ReadFileLine(hFile, LineBuffer, sizeof(LineBuffer));
		
		if(LineBuffer[0] == EOS)
		{
			count++;
			continue;
		}	
		else if(GetStringArgumentCount(LineBuffer, sizeof(LineBuffer)) != 2)
		{
			count++;
			continue;
		}	
		
		WriteFileLine(hTempFile, LineBuffer);
	}
	
	CloseHandle(hFile);
	CloseHandle(hTempFile);
	DeleteFile(Path);
	RenameFile(Path, TempFilePath);
	
	return count;
}

stock GetStringArgumentCount(const String:source[], length)
{
	new String:dummy_str[length];
	new count = 0, arglen;
	
	while((arglen = BreakString(source[arglen], dummy_str, length)) != -1)
		count++;
		
	if(count > 0)
		count++; // It always rushes one count ahead as it gives index to next argument, if a string has two arguments, only one arglen will be taken in a loop.
		
	return count;
}

// returns true if found, false otherwise.

stock bool:ReadServerValue(const String:Key[], String:buffer[], bufferlen)
{
	new String:FilePath[PLATFORM_MAX_PATH];
	
	BuildPath(Path_SM, FilePath, sizeof(FilePath), ServerValuesPath);
	
	if(!FileExists(FilePath))
		return false;
	
	new Handle:hFile = OpenFile(FilePath, "r");
	
	if(hFile == INVALID_HANDLE)
		return false;
	
	new String:LineBuffer[256], len, String:KeyBuffer[128];
	while(!IsEndOfFile(hFile))
	{
		ReadFileLine(hFile, LineBuffer, sizeof(LineBuffer));
		
		len = BreakString(LineBuffer, KeyBuffer, sizeof(KeyBuffer));
		
		if(StrEqual(Key, KeyBuffer))
		{
			BreakString(LineBuffer[len], buffer, bufferlen);
			
			CloseHandle(hFile);
			return true;
		}
	}

	CloseHandle(hFile);
	return false;
}

stock CreateEmptyFile(const String:Path[])
{
	CloseHandle(OpenFile(Path, "a"));
}
NICE!!

i will test this plugin. thanks for your time !!
Dr.Mohammad is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 04-02-2019 , 12:13   Re: [CSGO] IsCookieTrue !!
Reply With Quote #6

Quote:
Originally Posted by Dr.Mohammad View Post
NICE!!

i will test this plugin. thanks for your time !!
Lmao I literally told you it doesn't work in capital letter.

I just forgot how to implement overwriting.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334

Last edited by eyal282; 04-02-2019 at 12:13.
eyal282 is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 04-02-2019 , 13:15   Re: [CSGO] IsCookieTrue !!
Reply With Quote #7

bro

Code:
return Int_Value == 1;
__________________
retired
shavit is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 04-02-2019 , 18:17   Re: [CSGO] IsCookieTrue !!
Reply With Quote #8

Using Dynamic.

https://github.com/ntoxin66/Dynamic/...etting-Objects

Code:
Dynamic settings = Dynamic.GetSettings();
https://github.com/ntoxin66/Dynamic/...essing-Members

Code:
dynamic.SetBool("Bool", false);
dynamic.SetDynamic("Dynamic", INVALID_DYNAMIC_OBJECT);
dynamic.SetFloat("Float", 0.0);
dynamic.SetHandle("Handle", null);
dynamic.SetInt("Int", 0);
dynamic.SetString("String", "");
dynamic.SetVector("Vector", NULL_VECTOR
Code:
bvalue = dynamic.GetBool("Bool");
dvalue = dynamic.GetDynamic("Dynamic");
fvalue = dynamic.GetFloat("Float");
hvalue = dynamic.GetHandle("Handle");
ivalue = dynamic.GetInt("Int");
dynamic.GetString("String", svalue, sizeof(svalue));
dynamic.GetVector("Vector", vvalue);
https://github.com/ntoxin66/Dynamic/...namic.inc#L108

Code:
dynamic.ReadKeyValues("cfg/sourcemod/test.cfg");
Code:
dynamic.WriteKeyValues("cfg/sourcemod/test.cfg");
__________________

Last edited by Neuro Toxin; 04-02-2019 at 18:19.
Neuro Toxin is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:58.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode