Skip to content

Commit

Permalink
* Added support for up to 32 items in starting items (the items you r…
Browse files Browse the repository at this point in the history
…eceive when creating a new character).

Signed-off-by: Matheus Macabu <mkbu95@gmail.com>
  • Loading branch information
macabu committed Apr 20, 2013
1 parent 37e37c1 commit 5dbbbab
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
8 changes: 3 additions & 5 deletions conf/char-server.conf
Expand Up @@ -94,11 +94,9 @@ save_log: yes
// Start point, Map name followed by coordinates (x,y)
start_point: new_1-1,53,111

// Starting weapon for new characters
start_weapon: 1201

// Starting armor for new characters
start_armor: 2301
// Starting items for new characters
// Format is: id1,qt1,idn,qtn
start_items: 1201,1,2301,1

// Starting zeny for new characters
start_zeny: 0
Expand Down
43 changes: 25 additions & 18 deletions src/char/char.c
Expand Up @@ -125,8 +125,7 @@ int max_connect_user = -1;
int gm_allow_group = -1;
int autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
int start_zeny = 0;
int start_weapon = 1201;
int start_armor = 2301;
int start_items[64]; //32 starting items allowed [mkbu95]
int guild_exp_rate = 100;

//Custom limits for the fame lists. [Skotlex]
Expand Down Expand Up @@ -1530,7 +1529,7 @@ int make_new_char_sql(struct char_session_data* sd, char* name_, int str, int ag

char name[NAME_LENGTH];
char esc_name[NAME_LENGTH*2+1];
int char_id, flag;
int char_id, flag, k;

safestrncpy(name, name_, NAME_LENGTH);
normalize_name(name,TRIM_CHARS);
Expand Down Expand Up @@ -1594,13 +1593,10 @@ int make_new_char_sql(struct char_session_data* sd, char* name_, int str, int ag
//Retrieve the newly auto-generated char id
char_id = (int)Sql_LastInsertId(sql_handle);
//Give the char the default items
if (start_weapon > 0) { //add Start Weapon (Knife?)
if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` (`char_id`,`nameid`, `amount`, `identify`) VALUES ('%d', '%d', '%d', '%d')", inventory_db, char_id, start_weapon, 1, 1) )
Sql_ShowDebug(sql_handle);
}
if (start_armor > 0) { //Add default armor (cotton shirt?)
if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` (`char_id`,`nameid`, `amount`, `identify`) VALUES ('%d', '%d', '%d', '%d')", inventory_db, char_id, start_armor, 1, 1) )
Sql_ShowDebug(sql_handle);

for (k = 0; k < ARRAYLENGTH(start_items) && start_items[k] != 0; k += 2) {
if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` (`char_id`,`nameid`, `amount`, `identify`) VALUES ('%d', '%d', '%d', '%d')", inventory_db, char_id, start_items[k], start_items[k + 1], 1) )
Sql_ShowDebug(sql_handle);
}

ShowInfo("Created char: account: %d, char: %d, slot: %d, name: %s\n", sd->account_id, char_id, slot, name);
Expand Down Expand Up @@ -4812,18 +4808,29 @@ int char_config_read(const char* cfgName)
ShowError("Specified start_point %s not found in map-index cache.\n", map);
start_point.x = x;
start_point.y = y;
} else if (strcmpi(w1, "start_items") == 0) {
int i;
char *split, *split2;

i = 0;
split = strtok(w2, ",");
while (split != NULL) {

This comment has been minimized.

Copy link
@lighta

lighta Apr 21, 2013

Contributor

while (split != NULL && i < ARRAYLENGTH(start_items))
so we avoid array overbound and servcrash. (well we might do it differently to display a message error when limit is reached)

split2 = split;
split = strtok(NULL, ",");
start_items[i] = atoi(split2);
if (start_items[i] < 0)
start_items[i] = 0;
++i;
}

if (i%2) { //we know it must be a even number
ShowError("Specified 'start_items' is missing a parameter. Removing '%d'.\n", start_items[i - 1]);
start_items[i - 1] = 0;
}
} else if (strcmpi(w1, "start_zeny") == 0) {
start_zeny = atoi(w2);
if (start_zeny < 0)
start_zeny = 0;
} else if (strcmpi(w1, "start_weapon") == 0) {
start_weapon = atoi(w2);
if (start_weapon < 0)
start_weapon = 0;
} else if (strcmpi(w1, "start_armor") == 0) {
start_armor = atoi(w2);
if (start_armor < 0)
start_armor = 0;
} else if(strcmpi(w1,"log_char")==0) { //log char or not [devil]
log_char = atoi(w2);
} else if (strcmpi(w1, "unknown_char_name") == 0) {
Expand Down

0 comments on commit 5dbbbab

Please sign in to comment.