viewing paste ra-pin-lemon | Diff

Posted on the
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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
Index: src/common/mmo.h
===================================================================
--- src/common/mmo.h    (revision 17237)
+++ src/common/mmo.h    (working copy)
@@ -122,6 +122,8 @@
 //For Map Names, which the client considers to be 16 in length including the .gat extension
 #define MAP_NAME_LENGTH (11 + 1)
 #define MAP_NAME_LENGTH_EXT (MAP_NAME_LENGTH + 4)
+//Pincode Length
+#define PINCODE_LENGTH 4
 
 #define MAX_FRIENDS 40
 #define MAX_MEMOPOINTS 3
Index: src/login/login.c
===================================================================
--- src/login/login.c   (revision 17237)
+++ src/login/login.c   (working copy)
@@ -552,8 +552,10 @@
                uint8 char_slots = 0;
                int group_id = 0;
                char birthdate[10+1] = "";
-               char pincode[4+1] = "";
+               char pincode[PINCODE_LENGTH+1];
 
+               memset(pincode,0,PINCODE_LENGTH+1);
+
                int account_id = RFIFOL(fd,2);
                RFIFOSKIP(fd,6);
 
Index: src/login/account.h
===================================================================
--- src/login/account.h (revision 17237)
+++ src/login/account.h (working copy)
@@ -50,7 +50,7 @@
    char lastlogin[24];     // date+time of last successful login
    char last_ip[16];       // save of last IP of connection
    char birthdate[10+1];   // assigned birth date (format: YYYY-MM-DD, default: 0000-00-00)
-   char pincode[4+1];      // pincode system
+   char pincode[PINCODE_LENGTH+1];     // pincode system
    time_t pincode_change;  // (timestamp): last time of pincode change
    int account_reg2_num;
    struct global_reg account_reg2[ACCOUNT_REG2_NUM]; // account script variables (stored on login server)
Index: src/char/char.c
===================================================================
--- src/char/char.c (revision 17237)
+++ src/char/char.c (working copy)
@@ -29,6 +29,7 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <malloc.h>
 
 #define CHAR_MAX_MSG 300
 static char* msg_table[CHAR_MAX_MSG]; // Login Server messages_conf
@@ -132,8 +133,8 @@
    char new_name[NAME_LENGTH];
    char birthdate[10+1];  // YYYY-MM-DD
    // Pincode system
-   char pincode[4+1];
-   uint16 pincode_seed;
+   char pincode[PINCODE_LENGTH+1];
+   uint64 pincode_seed;
    time_t pincode_change;
    uint16 pincode_try;
    // Addon system
@@ -168,7 +169,7 @@
 void pincode_sendstate( int fd, struct char_session_data* sd, uint16 state );
 void pincode_notifyLoginPinUpdate( int account_id, char* pin );
 void pincode_notifyLoginPinError( int account_id );
-void pincode_decrypt( unsigned long userSeed, char* pin );
+void pincode_decrypt( uint64 userSeed, char* pin );
 int pincode_compare( int fd, struct char_session_data* sd, char* pin );
 
 // Addon system
@@ -4275,11 +4276,9 @@
            if( RFIFOREST(fd) < 10 )
                return 0;
 
-           if( RFIFOL(fd,2) != sd->account_id )
-               break;
+           if( pincode_enabled && RFIFOL(fd,2) == sd->account_id )
+               pincode_check( fd, sd );
 
-           pincode_check( fd, sd );
-
            RFIFOSKIP(fd,10);
        break;
 
@@ -4288,13 +4287,12 @@
            if( RFIFOREST(fd) < 6 )
                return 0;
 
-           if( RFIFOL(fd,2) != sd->account_id )
-               break;
-
-           if( strlen( sd->pincode ) <= 0 ){
-               pincode_sendstate( fd, sd, PINCODE_NEW );
-           }else{
-               pincode_sendstate( fd, sd, PINCODE_ASK );
+           if( pincode_enabled && RFIFOL(fd,2) == sd->account_id ){
+               if( strlen( sd->pincode ) <= 0 ){
+                   pincode_sendstate( fd, sd, PINCODE_NEW );
+               }else{
+                   pincode_sendstate( fd, sd, PINCODE_ASK );
+               }
            }
 
            RFIFOSKIP(fd,6);
@@ -4305,11 +4303,9 @@
            if( RFIFOREST(fd) < 14 )
                return 0;
 
-           if( RFIFOL(fd,2) != sd->account_id )
-               break;
+           if( pincode_enabled && RFIFOL(fd,2) == sd->account_id )
+               pincode_change( fd, sd );
 
-           pincode_change( fd, sd );
-
            RFIFOSKIP(fd,14);
        break;
 
@@ -4318,11 +4314,9 @@
            if( RFIFOREST(fd) < 10 )
                return 0;
 
-           if( RFIFOL(fd,2) != sd->account_id )
-               break;
+           if( pincode_enabled && RFIFOL(fd,2) == sd->account_id )
+               pincode_setnew( fd, sd );
 
-           pincode_setnew( fd, sd );
-
            RFIFOSKIP(fd,10);
        break;
 
@@ -4520,9 +4514,12 @@
 //Pincode system
 //------------------------------------------------
 void pincode_check( int fd, struct char_session_data* sd ){
-   char pin[5] = "\0\0\0\0";
-   strncpy((char*)pin, (char*)RFIFOP(fd, 6), 4+1);
+   char pin[PINCODE_LENGTH+1];
 
+   memset(pin,0,PINCODE_LENGTH+1);
+
+   strncpy((char*)pin, (char*)RFIFOP(fd, 6), PINCODE_LENGTH);
+
    pincode_decrypt(sd->pincode_seed, pin );
 
    if( pincode_compare( fd, sd, pin ) ){
@@ -4531,7 +4528,7 @@
 }
 
 int pincode_compare( int fd, struct char_session_data* sd, char* pin ){
-   if( strcmp( sd->pincode, pin ) == 0 ){
+   if( strncmp( sd->pincode, pin, PINCODE_LENGTH ) == 0 ){
        sd->pincode_try = 0;
        return 1;
    }else{
@@ -4546,27 +4543,33 @@
 }
 
 void pincode_change( int fd, struct char_session_data* sd ){
-   char oldpin[5] = "\0\0\0\0";
-   char newpin[5] = "\0\0\0\0";
+   char oldpin[PINCODE_LENGTH+1];
+   char newpin[PINCODE_LENGTH+1];
 
-   strncpy(oldpin, (char*)RFIFOP(fd,6), 4+1);
+   memset(oldpin,0,PINCODE_LENGTH+1);
+   memset(newpin,0,PINCODE_LENGTH+1);
+
+   strncpy(oldpin, (char*)RFIFOP(fd,6), PINCODE_LENGTH);
    pincode_decrypt(sd->pincode_seed,oldpin);
 
    if( !pincode_compare( fd, sd, oldpin ) )
        return;
 
-   strncpy(newpin, (char*)RFIFOP(fd,10), 4+1);
+   strncpy(newpin, (char*)RFIFOP(fd,10), PINCODE_LENGTH);
    pincode_decrypt(sd->pincode_seed,newpin);
 
    pincode_notifyLoginPinUpdate( sd->account_id, newpin );
+   strncpy(sd->pincode, newpin, sizeof(newpin));
 
    pincode_sendstate( fd, sd, PINCODE_PASSED );
 }
 
 void pincode_setnew( int fd, struct char_session_data* sd ){
-   char newpin[5] = "\0\0\0\0";
+   char newpin[PINCODE_LENGTH+1];
 
-   strncpy( newpin, (char*)RFIFOP(fd,6), 4+1 );
+   memset(newpin,0,PINCODE_LENGTH+1);
+
+   strncpy( newpin, (char*)RFIFOP(fd,6), PINCODE_LENGTH );
    pincode_decrypt( sd->pincode_seed, newpin );
 
    pincode_notifyLoginPinUpdate( sd->account_id, newpin );
@@ -4597,7 +4600,7 @@
    WFIFOHEAD(login_fd,11);
    WFIFOW(login_fd,0) = 0x2738;
    WFIFOL(login_fd,2) = account_id;
-   strncpy( (char*)WFIFOP(login_fd,6), pin, 5 );
+   strncpy( (char*)WFIFOP(login_fd,6), pin, PINCODE_LENGTH+1 );
    WFIFOSET(login_fd,11);
 }
 
@@ -4608,26 +4611,33 @@
    WFIFOSET(login_fd,6);
 }
 
-void pincode_decrypt( unsigned long userSeed, char* pin ){
+void pincode_decrypt( uint64 userSeed, char* pin ){
    int i, pos;
    char tab[10] = {0,1,2,3,4,5,6,7,8,9};
-   unsigned long multiplier = 0x3498, baseSeed = 0x881234;
+   uint64 multiplier = 0x3498, baseSeed = 0x881234;
 
+   ShowInfo("pinraw = %s \n",pin);
    for( i = 1; i < 10; i++ ){
        userSeed = baseSeed + userSeed * multiplier;
        pos = userSeed % (i + 1);
        if( i != pos ){
-           tab[i] ^= tab[pos];
+           tab[i] ^= tab[pos]; //x = x xor y; i != j
            tab[pos] ^= tab[i];
            tab[i] ^= tab[pos];
        }
    }
 
-   for( i = 0; i < 4; i++ ){
-       pin[i] = tab[pin[i]- '0'];
+   ShowInfo("pinin = %s \n",pin);
+// for( i = 0; i < PINCODE_LENGTH; i++ )
+//     pin[i] = tab[atoi(pin+i)];
+// ShowInfo("pininout=%s \n",pin);
+
+   for( i = 0; i < PINCODE_LENGTH; i++ ){
+       char tmp = tab[atoi(pin+i-1)];
+       ShowInfo("tmp = %d \n",tmp);
+       sprintf( pin+i, "%d", tmp);
    }
-
-   sprintf(pin, "%d%d%d%d", pin[0], pin[1], pin[2], pin[3]);
+   ShowInfo("pinout=%s \n",pin);
 }
 
 //------------------------------------------------
@@ -5018,6 +5028,13 @@
            guild_exp_rate = atoi(w2);
        } else if (strcmpi(w1, "pincode_enabled") == 0) {
            pincode_enabled = config_switch(w2);
+
+           #if PACKETVER < 20110309
+           if( pincode_enabled ) {
+               ShowWarning("pincode_enabled requires PACKETVER 20110309 or higher. Disabling...\n");
+               pincode_enabled = false;
+           }
+           #endif
        } else if (strcmpi(w1, "pincode_changetime") == 0) {
            pincode_changetime = atoi(w2)*60*60*24;
        } else if (strcmpi(w1, "pincode_maxtry") == 0) {
Viewed 1206 times, submitted by lighta.