Gamemode by include
#24

Quote:
Originally Posted by azzerking
View Post
Here is an example of how I lay things out

Code:
- {Name of Project} (Folder)
    - Config ( Core )
        - base.pwn ( Global Definitions, MySQL, Server Settings )
        - macros.pwn ( Global Macros for shortcuts like FUNCTION: and PUBLIC: )
        - plugins.pwn ( Global Plugin Definitions )
    - Player ( Module ) // The Prefix will be PD for PLAYER_DATA the name of the ENUM ( E_PLAYER_DATA )
        - init.pwn ( Includes, Initialize and Deinitialize functions )
        - config.pwn ( Enums, Definitions, Variables )
        - functions.pwn ( IsPlayerLoggedIn, etc )
        - database.pwn ( DB Functions / Threaded Query )
        - callbacks.pwn ( Prefixed Names, PD_OnPlayerConnect )
        - dialogs.pwn ( Functions / Responses )
        - textdraws.pwn ( Functions / Callbacks )
        - commands.pwn ( Player / Admin Commands )
        // You can just add a file for each section, pickups / objects, etc
 
     bootstrap.pwn // includes all modules and core files, so main gamemode only needs to include this file.
I hope this helps, I find this method to work the best for me, since I know whats in the file just by the name of it.

As for your mysql idea I find this to be a better way.

Code:
#define 	ENVIORNMENT 		        ( 0 ) 		// 0 - Production, 1 - Local Development, 2 - Remote Development

#define 	MYSQL_REMOTE_HOST 		"xxx.xxx.xxx.xxxx"
#define    	MYSQL_REMOTE_USER 		"server_name"
#define 	MYSQL_REMOTE_PASS 		"server_password"
#define 	MYSQL_REMOTE_TABLE 		"server_table"

#define 	MYSQL_LOCAL_HOST 		"xxx.xxx.xxx.xxxx"
#define    	MYSQL_LOCAL_USER 		"server_name"
#define 	MYSQL_LOCAL_PASS 		"server_password"
#define 	MYSQL_LOCAL_TABLE 		"server_table"

#define 	MYSQL_PRODUCTION_HOST 	"xxx.xxx.xxx.xxxx"
#define    	MYSQL_PRODUCTION_USER 	"server_name"
#define 	MYSQL_PRODUCTION_PASS 	"server_password"
#define 	MYSQL_PRODUCTION_TABLE 	"server_table"


// Now depending on how much you care, not that it makes much difference that you should, you can either use #if and #endif
// or you can a switch statment, I prefer swtich as it looks cleaner, and I love clean code.

new 
	database_connection
;

stock mysql_connect_ex()
{
	switch( ENVIORNMENT )
	{
		case 0: database_connection = mysql_connect( MYSQL_PRODUCTION_HOST, MYSQL_PRODUCTION_USER, MYSQL_PRODUCTION_PASS, MYSQL_PRODUCTION_TABLE );	
		case 1: database_connection = mysql_connect( MYSQL_LOCAL_HOST, MYSQL_LOCAL_USER, MYSQL_LOCAL_PASS, MYSQL_LOCAL_TABLE );
		case 2: database_connection = mysql_connect( MYSQL_REMOTE_HOST, MYSQL_REMOTE_USER, MYSQL_REMOTE_PASS, MYSQL_REMOTE_TABLE );
	}

	return database_connection;
}
I've 2 connection's type : when i'm on local (OnTestServer) and when I'm not. I'm using OnTestServer in differents commands like /ban, etc..
For this:
Code:
    - Config ( Core )
        - base.pwn ( Global Definitions, MySQL, Server Settings )
        - macros.pwn ( Global Macros for shortcuts like FUNCTION: and PUBLIC: )
        - plugins.pwn ( Global Plugin Definitions )
I'm doing like this:
"../core/configuration.inc" (GM's inititialization)
"../core/MySQLConnections.inc" (Creating table, connection to mysql, etc...)
"../core/base.inc" (Macros and constants)
That's good?

Annnd..
I'm trying a new thing. It's for creating logs (from configuration.inc):
PHP Code:
new 
    
Log_Level:Log_Server,
    ...;
enum Log_Level:LogType
{
    
NOTHING,
    
COMMANDS,
    
TCHAT,
    
FULL_LOG NOTHING COMMANDS TCHAT
};
stock CreateServerLog(Log_Level:Log_Serv Log_Level:FULL_LOG)
{
    
Log_Server Log_Serv;
    if(
_:Log_Serv == NOTHING)
        return print(
"[SERVER] Aucun log crйй."), 1;
    static
        
string[120],
        
hour,
        
minu,
        
sec,
        
day,
        
month,
        
year;
    
Get@SetWorldTime(hourminusec);
    
getdate(yearmonthday);
    
format(stringsizeof(string), "-------- Dйbut -------- [%02i/%02i/%02i] - %02ih %02imin %02is."daymonthyearhourminusec);
    
WriteLogs("AllCommands.txt"string);
    print(
"[SERVER] Logs configurйs.")
    return 
1;
}
stock Get@SetWorldTime(&hour = -1, &minutes = -1, &seconds = -1)
{
    
gettime(hourminusec);
    
SetWorldTime(hour);

Log_Server is gonna be used when writing logs.

EDIT: Write logs function
PHP Code:
WriteLogs(file[70], const reason[], playerid INVALID_PLAYER_ID)
{
    if(!
_:Log_Server)
        return 
1;
    static     
day,
            
month,
            
hour,
            
minute,
            
seconde,
            
year;
    static    
stringW[190];
    if(
strfind(file".txt"false0) == -1format(filesizeof(file), "%s.txt"file);
    new 
File:pos=fopen(fileio_append);
    if(!
pos)
    {
        
printf("[Server] Write Logs Error | Reason : pos=fopen Error | File : '%s' | Reason: '%s'"filereason);
        
SendMessageToAdmins(RED"[Server] "SAUMON_U" Une erreur est survenue dans les logs. Merci de vйrifier ceux-ci!");
        
SendMessageToAdmins(RED"[Server] "SAUMON_U"Fichier : '%s' | Contenus : '%s'"filereason);
        return 
1;
    } 
    
    
gettime(hourminuteseconde);
    
getdate(yearmonthday);
    if(!
strcmp(file"AllCommands.txt") && _:Log_Server == L_COMMANDS)
        
format(stringW,sizeof(stringW),"\r\n[%i] [%02i/%02i/%02i] %02i:%02i:%02i %s | '%s'"CmdID++, daymonthyearhourminutesecondeplayerid != INVALID_PLAYER_ID GetName(playeridtrue) : "ALL"reason);
    else if(!
strcmp(file"AllTChat.txt") && _:Log_Server == L_TCHAT)
        
format(stringW,sizeof(stringW),"\r\n[%02i/%02i/%02i] %02i:%02i:%02i %s (Player #%i) » '%s'"daymonthyearhourminutesecondeplayerid != INVALID_PLAYER_ID GetName(playeridtrue) : "ALL"p_NameOff{playerid}, reason);
    else if(
_:Log_Server == L_TCHAT)
        
format(stringW,sizeof(stringW),"\r\n[%02i/%02i/%02i] %02i:%02i:%02i %s | '%s'"daymonthyearhourminutesecondeplayerid != INVALID_PLAYER_ID GetName(playeridtrue) : "ALL"reason);
    
fwrite(pos,stringW);
    
fclose(pos);
    return 
1;

Reply


Messages In This Thread
Gamemode by include - by Dayrion - 22.02.2017, 12:48
Re: Gamemode by include - by jlalt - 22.02.2017, 12:53
Re: Gamemode by include - by Dayrion - 22.02.2017, 13:17
Re: Gamemode by include - by jlalt - 22.02.2017, 13:25
Re: Gamemode by include - by Dayrion - 22.02.2017, 14:52
Re: Gamemode by include - by jlalt - 22.02.2017, 14:57
Re: Gamemode by include - by PrO.GameR - 22.02.2017, 19:44
Re: Gamemode by include - by iKarim - 23.02.2017, 06:13
Re: Gamemode by include - by Sew_Sumi - 23.02.2017, 06:20
Re: Gamemode by include - by Yashas - 23.02.2017, 06:52
Re: Gamemode by include - by iKarim - 23.02.2017, 19:41
Re: Gamemode by include - by Dayrion - 23.02.2017, 23:47
Re: Gamemode by include - by Sew_Sumi - 24.02.2017, 00:50
Re: Gamemode by include - by iKarim - 24.02.2017, 05:17
Re: Gamemode by include - by DRIFT_HUNTER - 24.02.2017, 05:24
Re: Gamemode by include - by Sew_Sumi - 24.02.2017, 05:35
Re: Gamemode by include - by Gammix - 24.02.2017, 07:34
Re: Gamemode by include - by Dayrion - 24.02.2017, 10:21
Re: Gamemode by include - by DRIFT_HUNTER - 24.02.2017, 14:28
Re: Gamemode by include - by patrickgtr - 24.02.2017, 14:32
Re: Gamemode by include - by iKarim - 24.02.2017, 14:59
Re: Gamemode by include - by Dayrion - 01.03.2017, 22:27
Re: Gamemode by include - by azzerking - 01.03.2017, 23:41
Re: Gamemode by include - by Dayrion - 02.03.2017, 12:52
Re: Gamemode by include - by azzerking - 02.03.2017, 18:00
Re: Gamemode by include - by renatog - 02.03.2017, 19:50
Re: Gamemode by include - by Dayrion - 02.03.2017, 20:15
Re: Gamemode by include - by renatog - 02.03.2017, 20:58
Re: Gamemode by include - by Mauzen - 03.03.2017, 03:46
Re: Gamemode by include - by Y_Less - 03.03.2017, 10:25
Re: Gamemode by include - by RyderX - 03.03.2017, 10:49

Forum Jump:


Users browsing this thread: 2 Guest(s)