Pages

Create Coins ID Dekaron

[HOWTO] Create Coins ID
Every character that did visit the D-Shop gets a unique ID, witch is different from the user_no
I know its retarded but we have to deal with it
so lets look at the SP in the database:
/****** Object:  Stored Procedure dbo.BL_CreateIdCode    Script Date: 2006-5-25 13:03:36 ******/ 
CREATE PROCEDURE  dbo.BL_CreateIdCode @o_id_code        varchar(20)         OUTPUT     AS BEGIN 
     
    
DECLARE @serv_code  char(2) 
    DECLARE @
rand_seqno varchar(12) 
    DECLARE @
rand_code varchar(36) 
    
SET @serv_code = '01' 
    
SET @rand_code = newid()  
    
SET @rand_seqno = SubString(@rand_code, 1, 8) + SubString(@rand_code, 10, 4) 
    
SET @o_id_code = @serv_code + CONVERT(VARCHAR(6), GetDate(), 12) +  @rand_seqno 

END 

GO  
And his user_no is: 09082414173865
but we dont need that yet!

we need to create a code like: 010909167956B7D86FEB

01 => The server ID code (normaly 01)
090916 => The date (year month day)
7956B7D86FEB => A random 12 number & letter code

we can make one with the following code
<?php 
//----------------------------------------------------- 
// This is for MSSQL newid() 
function create_newid($length, $characters){ 

    if (
$characters == ''){ return ''; } 
    
$chars_length = strlen($characters)-1; 
     
    
mt_srand((double)microtime()*1000000); 
     
    
$newid = ''; 
    while(
strlen($newid) < $length){ 
        
$rand_char = mt_rand(0, $chars_length); 
        
$newid .= $characters[$rand_char]; 
    } 
     
    return 
$newid; 

} 
//----------------------------------------------------- 


// Server code is always 01 
$serv_code = '01'; 
// Create a random code $rand_code = create_newid(12, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890'); 
// Get the ymd date $date = date("ymd"); 
// Add it all toghter $o_id_code = $serv_code . '' . $date . '' . $rand_code; 
// echo out the code echo $o_id_code;  
?>
 Now insert into a db
INSERT INTO user_cash 
    
( 
    
id, 
    
user_no, 
    
group_id, 
    
amount, 
    
free_amount 
    
) VALUES 
    
( 
    
$o_id_code, // the code we just created 
    
$i_user_no, // the user_no 
    
'01', // the group code => should be 01 
    
'0', // the amount 
    
'0' // the free amount 
    
)  
janvier1985
Ragezone