AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Module Coding (https://forums.alliedmods.net/forumdisplay.php?f=9)
-   -   <old>(map.h)<old> <new>problem with chars</new> (https://forums.alliedmods.net/showthread.php?t=164344)

Lightokun 08-10-2011 09:10

<old>(map.h)<old> <new>problem with chars</new>
 
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.

Arkshine 08-10-2011 09:40

Re: Module help (map.h)
 
You should have some message. Try meta refresh and see what it says.

Lightokun 08-10-2011 09:52

Re: Module help (map.h)
 
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.

Arkshine 08-10-2011 09:54

Re: Module help (map.h)
 
Attach the .so to see myself.

Lightokun 08-10-2011 09:57

Re: Module help (map.h)
 
1 Attachment(s)
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:8) 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:8) 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:58:30: [META] (debug:9) Calling engine:IsDedicatedServer()
L 08/10/2011 - 17:58:30: [META] (debug:9) Calling engine:IsDedicatedServer()

Arkshine 08-10-2011 10:01

Re: Module help (map.h)
 
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")

Lightokun 08-10-2011 10:03

Re: Module help (map.h)
 
Found the solution.
CPP = gcc-4.2.4
>>>>
CPP = g++-4.2.4

Lightokun 08-13-2011 06:28

Re: <old>(map.h)<old> <new>problem with chars</new>
 
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]


Shadows In Rain 08-13-2011 07:25

Re: <old>(map.h)<old> <new>problem with chars</new>
 
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);
}


Lightokun 08-13-2011 07:41

Re: <old>(map.h)<old> <new>problem with chars</new>
 
Lol. My bad. Thank you!


All times are GMT -4. The time now is 15:19.

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