FloooD / custom_cs2dsrv

Jermuk's custom Counter Strike 2D Server written in C and modified by FloooD and leegao.
173.192.35.85:36000
3 stars 0 forks source link

Parser command stubs #26

Closed leegao closed 13 years ago

leegao commented 13 years ago

The stub generator is scripted in src/generator.lua

format:

generate(cmd_name, fmt, minimum_args, identifiers_and_default_value...)

where cmd_name is found in http://cs2d.com/help.php?cat=server

fmt describes the types of each variable (s for char*/string, i for int, and f for float)

minimum_args is the number of required arguments (IE, certain arguments are optional, like duration of a ban, while others are not, like the ip of the banip command)

identifiers_and_default_values are either strings or tables. If it's a string, it contains the NAME of the identifier in c. If it's a table, it contains the NAME of the variable and the DEFAULT VALUE associated with that variable. If this is left empty, names like _1, _2, _3, ... will be used.

For example, given the following specification for banip banip Categories: server

Parameters:
ip (text): IP address
[duration] (-1 - 1440): Temporary ban duration in minutes (or 0 for infinite ban, or -1 for default temp ban time mp_tempbantime)

We can write a parser for this via

generate(
    "banip", -- The name of this command is banip
    "si", -- The command takes in a string and an integer (ip and duration)
    1, -- Only the first argument is required, the second is optional, hence we require at least 1 argument.
    "ip", -- The name of the first argument, which corresponds to the 's'
    {"duration", -1} -- The name of the second argument is duration, corresponding to the 'i' in fmt. We also know that the default value ought to be -1, so we use that as the second argument.
)

I'm too lazy to finish this (and have a physics lab soon), so do a few for me plz? :D

leegao commented 13 years ago

PS it's in the lee_experimental branch

FloooD commented 13 years ago

uh... lol k ill do that tomorrow after midterm

leegao commented 13 years ago

nvm, I wrote a python script to generate the missing stubs in generate.lua so it can generate the C file... there's irony in here somewhere I'm sure.

FloooD commented 13 years ago

lol python > lua > c ??????????????????????????????????????

leegao commented 13 years ago

http://i.imgur.com/ZyeCO.jpg

in parse.c, https://github.com/FloooD/custom_cs2dsrv/blob/master/src/parse.c#L1762

        if(!buf){
            buf = (char*)malloc(j);
            memcpy(buf, text, j);
            buf[j] = '\0';
            text+=j;
        }

totally forgot the '\0' first time around <_<

FloooD commented 13 years ago

rofl @ unix shell