summaryrefslogtreecommitdiff
path: root/src/char/char.c
blob: 2d3e466f397dd62987dd16a2899e6ef7901be1fb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL.
// Copyright (c) 2014 Evol developers

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "../../../common/HPMi.h"
#include "../../../common/malloc.h"
#include "../../../common/mmo.h"
#include "../../../common/socket.h"
#include "../../../common/strlib.h"
#include "../../../char/char.h"

#include "common/ip.h"
#include "char/char.h"
#include "char/config.h"

void echar_parse_char_login_map_server(int *fd)
{
    if (!inter_server_ip)
        return;

    const uint32 ipl = session[*fd]->client_addr;

    const char *const ip = ip2str(ipl, NULL);
    if (!checkAllowedIp(inter_server_ip, ip))
    {
        ShowNotice("Connection of the map-server from ip %s REFUSED.\n", ip);
        chr->login_map_server_ack(*fd, 3);
        hookStop();
    }
}

void echar_parse_char_create_new_char(int *fdPtr, struct char_session_data* sd)
{
    // ignore char creation disable option
    const int fd = *fdPtr;
    uint16 race = 0;
    uint8 sex = 0;

    if (sd->version >= 4)
    {
        race = RFIFOW(fd, 31);
        if (race < min_char_class || race > max_char_class)
        {
            chr->creation_failed(fd, -10);
            RFIFOSKIP(fd, 31 + 3);
            hookStop();
            return;
        }
        sex = RFIFOB(fd, 33);
        if (sex > 1 && sex != 99)
        {
            chr->creation_failed(fd, -11);
            RFIFOSKIP(fd, 31 + 3);
            hookStop();
            return;
        }
    }

    const int result = chr->make_new_char_sql(sd, (char*)RFIFOP(fd, 2), 1, 1, 1, 1, 1, 1, RFIFOB(fd, 26), RFIFOW(fd, 27), RFIFOW(fd, 29));
    if (result < 0)
    {
        chr->creation_failed(fd, result);
    }
    else
    {
        // retrieve data
        struct mmo_charstatus char_dat;
        chr->mmo_char_fromsql(result, &char_dat, false); //Only the short data is needed.

        if (sd->version >= 4)
        {
            char_dat.class_ = race;
            char_dat.sex = sex;

            chr->mmo_char_tosql(result, &char_dat);
        }
        chr->creation_ok(fd, &char_dat);

        // add new entry to the chars list
        sd->found_char[char_dat.slot] = result; // the char_id of the new char
    }
    if (sd->version >= 4)
        RFIFOSKIP(fd, 31 + 3);
    else
        RFIFOSKIP(fd, 31);
    hookStop();
}

void echar_creation_failed(int *fdPtr, int *result)
{
    const int fd = *fdPtr;
    WFIFOHEAD(fd, 3);
    WFIFOW(fd, 0) = 0x6e;
    /* Others I found [Ind] */
    /* 0x02 = Symbols in Character Names are forbidden */
    /* 0x03 = You are not eligible to open the Character Slot. */
    /* 0x0B = This service is only available for premium users.  */
    switch (*result)
    {
        case -1: WFIFOB(fd, 2) = 0x00; break; // 'Charname already exists'
        case -2: WFIFOB(fd, 2) = 0xFF; break; // 'Char creation denied'
        case -3: WFIFOB(fd, 2) = 0x01; break; // 'You are underaged'
        case -4: WFIFOB(fd, 2) = 0x03; break; // 'You are not eligible to open the Character Slot.'
        case -5: WFIFOB(fd, 2) = 0x02; break; // 'Symbols in Character Names are forbidden'
        case -10: WFIFOB(fd, 2) = 0x50; break; // Wrong class
        case -11: WFIFOB(fd, 2) = 0x51; break; // Wrong sex

        default:
            ShowWarning("chr->parse_char: Unknown result received from chr->make_new_char_sql: %d!\n", *result);
            WFIFOB(fd,2) = 0xFF;
            break;
    }
    WFIFOSET(fd,3);
    hookStop();
}