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

<old>(map.h)<old> <new>problem with chars</new>


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Lightokun
Member
Join Date: Oct 2009
Old 08-10-2011 , 09:10   <old>(map.h)<old> <new>problem with chars</new>
Reply With Quote #1

Just started to write first module and stuck.
I'm using map.h to fill a map with certain values.
The code:
Code:
#include <map.h>
#include <string>
#include "amxxmodule.h"

struct Node {
	char *name;
	char *auth;
	char *flags;
	int sid;
	int fid;
	int red;
};

Node node;
std::map<std::string, Node> admin_map;

static cell AMX_NATIVE_CALL admin_list_addadmin(AMX *amx,cell *params)
{
	int length;
	char *name = MF_GetAmxString(amx, params[1], 0, &length);
	char *auth = MF_GetAmxString(amx, params[2], 1, &length);
	char *flags = MF_GetAmxString(amx, params[3], 2, &length);
	
	node.name = name;
	node.auth = auth;
	node.flags = flags;
	node.sid = params[4];
	node.fid = params[6];
	node.red = 0;
	
	MF_Log("Inserting %s with token %s", name, auth);
	//admin_map.insert(std::make_pair(auth,node));
	admin_map[auth] = node;

	return 1;
}

static cell AMX_NATIVE_CALL admin_list_isadmin(AMX *amx,cell *params)
{
	return 1;
}

AMX_NATIVE_INFO wtf_exports[] = 
{
	{ "admin_list_addadmin", admin_list_addadmin },
	{ "admin_list_isadmin", admin_list_isadmin },
	{ NULL, NULL }
};

void OnAmxxAttach()
{
	MF_AddNatives(wtf_exports);
}
The problem is here: admin_map[auth] = node;
When server starts, it says that module is bad load. When i remove this part of code (admin_map[auth] = node;) and recompile - everything (two natives) works fine.
Any help?
Linux, gcc-4.2.3.
__________________

Last edited by Lightokun; 08-13-2011 at 06:26.
Lightokun is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-10-2011 , 09:40   Re: Module help (map.h)
Reply With Quote #2

You should have some message. Try meta refresh and see what it says.
__________________
Arkshine is offline
Lightokun
Member
Join Date: Oct 2009
Old 08-10-2011 , 09:52   Re: Module help (map.h)
Reply With Quote #3

meta load addons/amxmodx/modules/epic_admin_amxx_i386.so
Couldn't load plugin '<epic_admin_amxx_i386.so>'; see log

Currently loaded plugins:
description stat pend file vers src load unlod
[ 1] AMX Mod X RUN - amxmodx_mm_i386. v1.8.2-d ini Start ANY
[ 2] MySQL RUN - mysql_amxx_i386. v1.8.2-d pl1 ANY ANY
[ 3] Orpheu RUN - orpheu_amxx_i386 v2.3 pl1 ANY ANY
[ 4] Fun RUN - fun_amxx_i386.so v1.8.2-d pl1 ANY ANY
[ 5] CStrike RUN - cstrike_amxx_i38 v1.8.2-d pl1 ANY ANY
[ 6] CSX RUN - csx_amxx_i386.so v1.8.2-d pl1 ANY ANY
[ 7] Engine RUN - engine_amxx_i386 v1.8.2-d pl1 ANY ANY
[ 8] FakeMeta RUN - fakemeta_amxx_i3 v1.8.2-d pl1 ANY ANY
[ 9] Ham Sandwich RUN - hamsandwich_amxx v1.8.2-d pl1 ANY ANY
[10] <epic_admin_amx badf load epic_admin_amxx_ v - cmd - -
10 plugins, 9 running

Nothing in logs.

-debug -dev is enabled. +log on.
__________________
Lightokun is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-10-2011 , 09:54   Re: Module help (map.h)
Reply With Quote #4

Attach the .so to see myself.
__________________
Arkshine is offline
Lightokun
Member
Join Date: Oct 2009
Old 08-10-2011 , 09:57   Re: Module help (map.h)
Reply With Quote #5

Here.

L 08/10/2011 - 17:58:28: [META] (debug:9) Calling engine:IsDedicatedServer()
L 08/10/2011 - 17:58:28: [META] (debug:9) Calling engine:IsDedicatedServer()
meta load addons/amxmodx/modules/epic_admin_amxx_i386.so
L 08/10/2011 - 17:58:29: [META] (debug:9) Calling engine:IsDedicatedServer()

L 08/10/2011 - 17:58:29: [META] (debug:2) Resolved 'addons/amxmodx/modules/epic_admin_amxx_i386.so' to file '/home/hlds_servers/hlds_cw/cstrike/addons/amxmodx/modules/epic_admin_amxx_i386.so'
L 08/10/2011 - 17:58:29: [META] (debug: Looking for loaded plugin with dlfnamepath: /home/hlds_servers/hlds_cw/cstrike/addons/amxmodx/modules/epic_admin_amxx_i386.so
L 08/10/2011 - 17:58:29: [META] (debug:9) Looking at: plugin amxmodx_mm_i386.so loadedpath: /home/hlds_servers/hlds_cw/cstrike/addons/amxmodx/dlls/amxmodx_mm_i386.so
L 08/10/2011 - 17:58:29: [META] (debug:9) Looking at: plugin mysql_amxx_i386.so loadedpath: /home/hlds_servers/hlds_cw/cstrike/addons/amxmodx/modules/mysql_amxx_i386.so
L 08/10/2011 - 17:58:29: [META] (debug:9) Looking at: plugin orpheu_amxx_i386.so loadedpath: /home/hlds_servers/hlds_cw/cstrike/addons/amxmodx/modules/orpheu_amxx_i386.so
L 08/10/2011 - 17:58:29: [META] (debug:9) Looking at: plugin fun_amxx_i386.so loadedpath: /home/hlds_servers/hlds_cw/cstrike/addons/amxmodx/modules/fun_amxx_i386.so
L 08/10/2011 - 17:58:29: [META] (debug:9) Looking at: plugin cstrike_amxx_i386.so loadedpath: /home/hlds_servers/hlds_cw/cstrike/addons/amxmodx/modules/cstrike_amxx_i386.so
L 08/10/2011 - 17:58:29: [META] (debug:9) Looking at: plugin csx_amxx_i386.so loadedpath: /home/hlds_servers/hlds_cw/cstrike/addons/amxmodx/modules/csx_amxx_i386.so
L 08/10/2011 - 17:58:29: [META] (debug:9) Looking at: plugin engine_amxx_i386.so loadedpath: /home/hlds_servers/hlds_cw/cstrike/addons/amxmodx/modules/engine_amxx_i386.so
L 08/10/2011 - 17:58:29: [META] (debug:9) Looking at: plugin fakemeta_amxx_i386.so loadedpath: /home/hlds_servers/hlds_cw/cstrike/addons/amxmodx/modules/fakemeta_amxx_i386.so
L 08/10/2011 - 17:58:29: [META] (debug:9) Looking at: plugin hamsandwich_amxx_i386.so loadedpath: /home/hlds_servers/hlds_cw/cstrike/addons/amxmodx/modules/hamsandwich_amxx_i386.so
L 08/10/2011 - 17:58:29: [META] (debug: No loaded plugin found with path: /home/hlds_servers/hlds_cw/cstrike/addons/amxmodx/modules/epic_admin_amxx_i386.so
L 08/10/2011 - 17:58:29: [META] ERROR: dll: Failed query plugin '<epic_admin_amxx_i386.so>'; Couldn't open file '/home/hlds_servers/hlds_cw/cstrike/addons/amxmodx/modules/epic_admin_amxx_i386.so': /home/hlds_servers/hlds_cw/cstrike/addons/amxmodx/modules/epic_admin_amxx_i386.so: undefined symbol: _ZNSaIcEC1Ev
L 08/10/2011 - 17:58:29: [META] ERROR: dll: Skipping plugin '<epic_admin_amxx_i386.so>'; couldn't query
Couldn't load plugin '<epic_admin_amxx_i386.so>'; see log
Currently loaded plugins:
description stat pend file vers src load unlod
[ 1] AMX Mod X RUN - amxmodx_mm_i386. v1.8.2-d ini Start ANY
[ 2] MySQL RUN - mysql_amxx_i386. v1.8.2-d pl1 ANY ANY
[ 3] Orpheu RUN - orpheu_amxx_i386 v2.3 pl1 ANY ANY
[ 4] Fun RUN - fun_amxx_i386.so v1.8.2-d pl1 ANY ANY
[ 5] CStrike RUN - cstrike_amxx_i38 v1.8.2-d pl1 ANY ANY
[ 6] CSX RUN - csx_amxx_i386.so v1.8.2-d pl1 ANY ANY
[ 7] Engine RUN - engine_amxx_i386 v1.8.2-d pl1 ANY ANY
[ 8] FakeMeta RUN - fakemeta_amxx_i3 v1.8.2-d pl1 ANY ANY
[ 9] Ham Sandwich RUN - hamsandwich_amxx v1.8.2-d pl1 ANY ANY
[10] <epic_admin_amx badf load epic_admin_amxx_ v - cmd - -
10 plugins, 9 running
L 08/10/2011 - 17:58:29: [META] (debug:9) Calling fakemeta_amxx_i386.so:GetGameDescription()
L 08/10/2011 - 17:58:29: [META] (debug:9) Skipped (supercede) cs_i386.so:GetGameDescription()
L 08/10/2011 - 17:58:29: [META] (debug:9) Calling engine:IsDedicatedServer()
L 08/10/2011 - 17:58:29: [META] (debug:9) Calling engine:IsDedicatedServer()
L 08/10/2011 - 17:580: [META] (debug:9) Calling engine:IsDedicatedServer()
L 08/10/2011 - 17:580: [META] (debug:9) Calling engine:IsDedicatedServer()
Attached Files
File Type: so epic_admin_amxx_i386.so (50.0 KB, 157 views)
__________________
Lightokun is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-10-2011 , 10:01   Re: Module help (map.h)
Reply With Quote #6

I got :

Quote:
AMXX] Module "cstrike/addons/amxmodx/modules/epic_admin_amxx_i386.so" failed to load (cstrike/addons/amxmodx/modules/epic_admin_amxx_i386.so: undefined symbol: _ZNSaIcEC1Ev)
[AMXX] Module is not a valid library (file "cstrike/addons/amxmodx/modules/epic_admin_amxx_i386.so")
__________________
Arkshine is offline
Lightokun
Member
Join Date: Oct 2009
Old 08-10-2011 , 10:03   Re: Module help (map.h)
Reply With Quote #7

Found the solution.
CPP = gcc-4.2.4
>>>>
CPP = g++-4.2.4
__________________
Lightokun is offline
Lightokun
Member
Join Date: Oct 2009
Old 08-13-2011 , 06:28   Re: <old>(map.h)<old> <new>problem with chars</new>
Reply With Quote #8

Another problem.
I'm new in C/C++

Someone can help and say me how to copy pointer value to variable without effect that i encountered?

Code:
#include <map.h>
#include <string>
#include <stdlib.h>
#include "amxxmodule.h"

struct Node {
	char *name;
	char *auth;
	char *flags;
	int sid;
	int fid;
	int red;
};

Node node;
std::map<std::string, Node> admin_map;

static cell AMX_NATIVE_CALL admin_list_addadmin(AMX *amx,cell *params)
{
	int length, size;
	
	char *name = MF_GetAmxString(amx, params[1], 0, &length);
	char *auth = MF_GetAmxString(amx, params[2], 1, &length);
	char *flags = MF_GetAmxString(amx, params[3], 2, &length);
	
	MF_Log("Was %s", name);
	
	size = strlen(name);
	char *sname = new char[size+1];
	strcpy(name, sname);
	MF_Log("Became %s", sname);
	MF_Log("");
	
	size = strlen(auth);
	char *sauth = new char[size+1];
	strcpy(auth, sauth);
	
	size = strlen(flags);
	char *sflags = new char[size+1];
	strcpy(flags, sflags);
	
	node.name = sname;
	node.auth = sauth;
	node.flags = sflags;
	node.sid = params[4];
	node.fid = params[6];
	node.red = 0;
	
	admin_map[auth] = node;

	return 1;
}

static cell AMX_NATIVE_CALL admin_list_isadmin(AMX *amx,cell *params)
{
	std::map<std::string, Node>::iterator i;
	
	for(i=admin_map.begin(); i!=admin_map.end(); ++i)
	{
		//MF_Log("Got name %s; auth: %s; flags: %s; sid: %d; fid: %d; red: %d", i->second.name, i->second.auth, i->second.flags, i->second.sid, i->second.fid, i->second.red);
		// 
	}

	//return set_amxstring(amx, params[5], f_flags, params[6]);
	return 1;
}

AMX_NATIVE_INFO wtf_exports[] = 
{
	{ "admin_list_addadmin", admin_list_addadmin },
	{ "admin_list_isadmin", admin_list_isadmin },
	{ NULL, NULL }
};

void OnAmxxAttach()
{
	MF_AddNatives(wtf_exports);
}
Output:
Code:
L 08/13/2011 - 14:23:55: [eAdm] Was .:MoMo_L:.>>
L 08/13/2011 - 14:23:55: [eAdm] Became
L 08/13/2011 - 14:23:55: [eAdm]
L 08/13/2011 - 14:23:55: [eAdm] Was <<ProVideR>>*no_song*[43rus]
L 08/13/2011 - 14:23:55: [eAdm] Became
L 08/13/2011 - 14:23:55: [eAdm]
L 08/13/2011 - 14:23:55: [eAdm] Was Dumba$$
L 08/13/2011 - 14:23:55: [eAdm] Became
L 08/13/2011 - 14:23:55: [eAdm]
L 08/13/2011 - 14:23:55: [eAdm] Was made by mammy^VooDoo^pro100pro
L 08/13/2011 - 14:23:55: [eAdm] Became
L 08/13/2011 - 14:23:55: [eAdm]
L 08/13/2011 - 14:23:55: [eAdm] Was blblbl4a
L 08/13/2011 - 14:23:55: [eAdm] Became
L 08/13/2011 - 14:23:55: [eAdm]
L 08/13/2011 - 14:23:55: [eAdm] Was CaHTa :D
L 08/13/2011 - 14:23:55: [eAdm] Became
L 08/13/2011 - 14:23:55: [eAdm]
L 08/13/2011 - 14:23:55: [eAdm] Was SmOKe
L 08/13/2011 - 14:23:55: [eAdm] Became
L 08/13/2011 - 14:23:55: [eAdm]
L 08/13/2011 - 14:23:55: [eAdm] Was stReet
L 08/13/2011 - 14:23:55: [eAdm] Became
L 08/13/2011 - 14:23:55: [eAdm]
__________________
Lightokun is offline
Shadows In Rain
Senior Member
Join Date: Apr 2010
Location: Russia::Siberia
Old 08-13-2011 , 07:25   Re: <old>(map.h)<old> <new>problem with chars</new>
Reply With Quote #9

You copying from destination to source lol.
BTW:
Code:
struct t_Node
{
	char name[33];
	char auth[33];
	char flags[27];
	int sid;
	int fid;
	int red;
	
	t_Node(const char * a_name, const char * a_auth, const char * a_flags, int a_sid, int a_fid, int a_red):
		sid(a_sid), fid(a_fid), red(a_red)
	{
		strncpy(name, a_name, sizeof(name) / sizeof(char) - 1);
		strncpy(auth, a_auth, sizeof(auth) / sizeof(char) - 1);
		strncpy(flags, a_flags, sizeof(flags) / sizeof(char) - 1);
	}
};

std::map<std::string, Node> admin_map;

static cell AMX_NATIVE_CALL admin_list_addadmin(AMX *amx,cell *params)
{
	const char *name = MF_GetAmxString(amx, params[1], 0, &length);
	const char *auth = MF_GetAmxString(amx, params[2], 1, &length);
	const char *flags = MF_GetAmxString(amx, params[3], 2, &length);

	admin_map[auth] = t_Node
	(
		name,
		auth,
		flags,
		params[4],
		params[6],
		0
	);

	return cell(~0);
}
__________________
I'm using Google translator, yarrr. |.◕‿‿◕.|

Last edited by Shadows In Rain; 08-13-2011 at 07:29.
Shadows In Rain is offline
Send a message via ICQ to Shadows In Rain
Lightokun
Member
Join Date: Oct 2009
Old 08-13-2011 , 07:41   Re: <old>(map.h)<old> <new>problem with chars</new>
Reply With Quote #10

Lol. My bad. Thank you!
__________________
Lightokun 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 01:26.


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