📄 bnchat.c
字号:
if (!(rpacket = packet_create(packet_class_bnet))) { fprintf(stderr,"%s: could not create packet\n",argv[0]); psock_close(client.sd); if (client.changed_in) tcsetattr(client.fd_stdin,TCSAFLUSH,&client.in_attr_old); return STATUS_FAILURE; } if (!(packet = packet_create(packet_class_bnet))) { fprintf(stderr,"%s: could not create packet\n",argv[0]); psock_close(client.sd); if (client.changed_in) tcsetattr(client.fd_stdin,TCSAFLUSH,&client.in_attr_old); return STATUS_FAILURE; } packet_set_size(packet,sizeof(t_client_fileinforeq)); packet_set_type(packet,CLIENT_FILEINFOREQ); bn_int_set(&packet->u.client_fileinforeq.type,CLIENT_FILEINFOREQ_TYPE_TOS); bn_int_set(&packet->u.client_fileinforeq.unknown2,CLIENT_FILEINFOREQ_UNKNOWN2); if ((user.clienttag == CLIENTTAG_DIABLO2DV) || (user.clienttag == CLIENTTAG_DIABLO2XP)) packet_append_string(packet,CLIENT_FILEINFOREQ_FILE_TOSUNICODEUSA); else packet_append_string(packet,CLIENT_FILEINFOREQ_FILE_TOSUSA); client_blocksend_packet(client.sd,packet); packet_del_ref(packet); do if (client_blockrecv_packet(client.sd,rpacket)<0) { fprintf(stderr,"%s: server closed connection\n",argv[0]); psock_close(client.sd); if (client.changed_in) tcsetattr(client.fd_stdin,TCSAFLUSH,&client.in_attr_old); return STATUS_FAILURE; } while (packet_get_type(rpacket)!=SERVER_FILEINFOREPLY); /* real client would also send statsreq on past logins here */ printf("----\n"); if (newacct) { if (client.useansi) ansi_text_color_fore(ansi_text_color_red); printf("###### Terms Of Service ######\n"); print_file(&client.saddr,packet_get_str_const(rpacket,sizeof(t_server_fileinforeply),1024),argv[0],user.clienttag); printf("##############################\n\n"); if (client.useansi) ansi_text_reset(); } for (;;) { char password[MAX_MESSAGE_LEN]; unsigned int i; int status; if (newacct) { char passwordvrfy[MAX_MESSAGE_LEN]; t_hash passhash1; printf("Enter information for your new account\n"); client.munged = 1; client.commpos = 0; user.player[0] = '\0'; while ((status = client_get_comm("Username: ",user.player,MAX_MESSAGE_LEN,&client.commpos, 1,client.munged,client.screen_width))==0) if (handle_winch) { client_get_termsize(client.fd_stdin,&client.screen_width,&client.screen_height); printf(" \r"); client.munged = 1; handle_winch = 0; } else client.munged = 0; printf("\n"); if (status<0) continue; if (strchr(user.player,' ') || strchr(user.player,'\t') || strchr(user.player,'\r') || strchr(user.player,'\n') ) { printf("Spaces are not allowed in usernames. Try again.\n"); continue; } /* we could use strcspn() but it doesn't exist everywhere */ if (strchr(user.player,'#') || strchr(user.player,'%') || strchr(user.player,'&') || strchr(user.player,'*') || strchr(user.player,'\\') || strchr(user.player,'"') || strchr(user.player,',') || strchr(user.player,'<') || strchr(user.player,'/') || strchr(user.player,'>') || strchr(user.player,'?')) { printf("The special characters #%%&*\\\",</>? are allowed in usernames. Try again.\n"); } if (strlen(user.player)>=USER_NAME_MAX) { printf("Usernames must not be more than %u characters long. Try again.\n",USER_NAME_MAX-1); continue; } client.munged = 1; client.commpos = 0; password[0] = '\0'; while ((status = client_get_comm("Password: ",password,MAX_MESSAGE_LEN,&client.commpos,0, client.munged,client.screen_width))==0) if (handle_winch) { client_get_termsize(client.fd_stdin,&client.screen_width,&client.screen_height); printf(" \r"); client.munged = 1; handle_winch = 0; } else client.munged = 0; printf("\n"); if (status<0) continue; if (strlen(password)>USER_PASS_MAX) { printf("password must not be more than %u characters long. Try again.\n",USER_PASS_MAX); continue; } for (i=0; i<strlen(password); i++) if (isupper((int)password[i])) password[i] = tolower((int)password[i]); client.munged = 1; client.commpos = 0; passwordvrfy[0] = '\0'; while ((status = client_get_comm("Retype password: ",passwordvrfy,MAX_MESSAGE_LEN,&client.commpos,0, client.munged,client.screen_width))==0) if (handle_winch) { client_get_termsize(client.fd_stdin,&client.screen_width,&client.screen_height); printf(" \r"); client.munged = 1; handle_winch = 0; } else client.munged = 0; printf("\n"); if (status<0) continue; for (i=0; i<strlen(passwordvrfy); i++) passwordvrfy[i] = tolower((int)passwordvrfy[i]); if (strcmp(password,passwordvrfy)!=0) { printf("Passwords do not match. Try again.\n"); continue; } bnet_hash(&passhash1,strlen(password),password); /* do the single hash */ if (!(packet = packet_create(packet_class_bnet))) { fprintf(stderr,"%s: could not create packet\n",argv[0]); psock_close(client.sd); if (client.changed_in) tcsetattr(client.fd_stdin,TCSAFLUSH,&client.in_attr_old); return STATUS_FAILURE; } packet_set_size(packet,sizeof(t_client_createacctreq1)); packet_set_type(packet,CLIENT_CREATEACCTREQ1); hash_to_bnhash((t_hash const *)&passhash1,packet->u.client_createacctreq1.password_hash1); /* avoid warning */ packet_append_string(packet,user.player); client_blocksend_packet(client.sd,packet); packet_del_ref(packet); do if (client_blockrecv_packet(client.sd,rpacket)<0) { fprintf(stderr,"%s: server closed connection\n",argv[0]); psock_close(client.sd); if (client.changed_in) tcsetattr(client.fd_stdin,TCSAFLUSH,&client.in_attr_old); return STATUS_FAILURE; } while (packet_get_type(rpacket)!=SERVER_CREATEACCTREPLY1); dprintf("Got CREATEACCTREPLY1\n"); if (bn_int_get(rpacket->u.server_createacctreply1.result)==SERVER_CREATEACCTREPLY1_RESULT_NO) { printf("Could not create an account under that name. Try another one.\n"); continue; } printf("Account created.\n"); } else if (changepass) { char passwordprev[MAX_MESSAGE_LEN]; char passwordvrfy[MAX_MESSAGE_LEN]; struct { bn_int ticks; bn_int sessionkey; bn_int passhash1[5]; } temp; t_hash oldpasshash1; t_hash oldpasshash2; t_hash newpasshash1; unsigned int ticks; printf("Enter your old and new login information\n"); client.munged = 1; client.commpos = 0; user.player[0] = '\0'; while ((status = client_get_comm("Username: ",user.player,MAX_MESSAGE_LEN,&client.commpos,1, client.munged,client.screen_width))==0) if (handle_winch) { client_get_termsize(client.fd_stdin,&client.screen_width,&client.screen_height); printf(" \r"); client.munged = 1; handle_winch = 0; } else client.munged = 0; printf("\n"); if (status<0) continue; if (strchr(user.player,' ')) { printf("Spaces not allowed in username. Try again.\n"); continue; } if (strlen(user.player)>=USER_NAME_MAX) { printf("Usernames must not be more than %u characters long. Try again.\n",USER_NAME_MAX-1); continue; } client.munged = 1; client.commpos = 0; passwordprev[0] = '\0'; while ((status = client_get_comm("Old password: ",passwordprev,MAX_MESSAGE_LEN,&client.commpos,0, client.munged,client.screen_width))==0) if (handle_winch) { client_get_termsize(client.fd_stdin,&client.screen_width,&client.screen_height); printf(" \r"); client.munged = 1; handle_winch = 0; } else client.munged = 0; printf("\n"); if (status<0) continue; for (i=0; i<strlen(passwordprev); i++) passwordprev[i] = tolower((int)passwordprev[i]); client.munged = 1; client.commpos = 0; password[0] = '\0'; while ((status = client_get_comm("New password: ",password,MAX_MESSAGE_LEN,&client.commpos,0, client.munged,client.screen_width))==0) if (handle_winch) { client_get_termsize(client.fd_stdin,&client.screen_width,&client.screen_height); printf(" \r"); client.munged = 1; handle_winch = 0; } else client.munged = 0; printf("\n"); if (status<0) continue; for (i=0; i<strlen(password); i++) password[i] = tolower((int)password[i]); client.munged = 1; client.commpos = 0; passwordvrfy[0] = '\0'; while ((status = client_get_comm("Retype new password: ",passwordvrfy,MAX_MESSAGE_LEN,&client.commpos,0, client.munged,client.screen_width))==0) if (handle_winch) { client_get_termsize(client.fd_stdin,&client.screen_width,&client.screen_height); printf(" \r"); client.munged = 1; handle_winch = 0; } else client.munged = 0; printf("\n"); if (status<0) continue; for (i=0; i<strlen(passwordvrfy); i++) passwordvrfy[i] = tolower((int)passwordvrfy[i]); if (strcmp(password,passwordvrfy)!=0) { printf("New passwords do not match. Try again.\n"); continue; } ticks = 0; /* FIXME: what to use here? */ bn_int_set(&temp.ticks,ticks); bn_int_set(&temp.sessionkey,client.sessionkey); bnet_hash(&oldpasshash1,strlen(passwordprev),passwordprev); /* do the single hash for old */ hash_to_bnhash((t_hash const *)&oldpasshash1,temp.passhash1); /* avoid warning */ bnet_hash(&oldpasshash2,sizeof(temp),&temp); /* do the double hash for old */ bnet_hash(&newpasshash1,strlen(password),password); /* do the single hash for new */ if (!(packet = packet_create(packet_class_bnet))) { fprintf(stderr,"%s: could not create packet\n",argv[0]); psock_close(client.sd); if (client.changed_in) tcsetattr(client.fd_stdin,TCSAFLUSH,&client.in_attr_old); return STATUS_FAILURE; } packet_set_size(packet,sizeof(t_client_changepassreq)); packet_set_type(packet,CLIENT_CHANGEPASSREQ); bn_int_set(&packet->u.client_changepassreq.ticks,ticks); bn_int_set(&packet->u.client_changepassreq.sessionkey,client.sessionkey); hash_to_bnhash((t_hash const *)&oldpasshash2,packet->u.client_changepassreq.oldpassword_hash2); /* avoid warning */ hash_to_bnhash((t_hash const *)&newpasshash1,packet->u.client_changepassreq.newpassword_hash1); /* avoid warning */ packet_append_string(packet,user.player); client_blocksend_packet(client.sd,packet); packet_del_ref(packet); do if (client_blockrecv_packet(client.sd,rpacket)<0) { fprintf(stderr,"%s: server closed connection\n",argv[0]); psock_close(client.sd); if (client.changed_in) tcsetattr(client.fd_stdin,TCSAFLUSH,&client.in_attr_old); return STATUS_FAILURE; } while (packet_get_type(rpacket)!=SERVER_CHANGEPASSACK); dprintf("Got CHANGEPASSACK\n"); if (bn_int_get(rpacket->u.server_changepassack.message)==SERVER_CHANGEPASSACK_MESSAGE_FAIL) { printf("Could not change password. Try again.\n"); continue; } printf("Password changed.\n"); } else { printf("Enter your login information\n"); client.munged = 1; client.commpos = 0; user.player[0] = '\0'; while ((status = client_get_comm("Username: ",user.player,MAX_MESSAGE_LEN,&client.commpos,1, client.munged,client.screen_width))==0) if (handle_winch) { client_get_termsize(client.fd_stdin,&client.screen_width,&client.screen_height); printf(" \r"); client.munged = 1; handle_winch = 0; } else client.munged = 0; printf("\n"); if (status<0) continue; if (strchr(user.player,' ')) { printf("Spaces not allowed in username. Try again.\n"); continue; } if (strlen(user.player)>=USER_NAME_MAX) { printf("Usernames must not be more than %u characters long. Try again.\n",USER_NAME_MAX-1); continue; } client.munged = 1; client.commpos = 0; password[0] = '\0'; while ((status = client_get_comm("Password: ",password,MAX_MESSAGE_LEN,&client.commpos,0, client.munged,client.screen_width))==0) if (handle_winch) { client_get_termsize(client.fd_stdin,&client.screen_width,&client.screen_height); printf(" \r"); client.munged = 1; handle_winch = 0; } else client.munged = 0; printf("\n"); if (status<0) continue; for (i=0; i<strlen(password); i++) password[i] = tolower((int)password[i]); } /* now login */ { struct { bn_int ticks; bn_int sessionkey; bn_int passhash1[5]; } temp; t_hash passhash1; t_hash passhash2; unsigned int ticks; ticks = 0; /* FIXME: what to use here? */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -