Fixed bug with nicknames

This commit is contained in:
Bazsalanszky 2019-10-28 21:58:23 +01:00
parent beb0a4eb98
commit 52267d12bd
Signed by: Bazsalanszky
GPG key ID: 214701A3BD4B06F2
3 changed files with 6 additions and 6 deletions

2
main.c
View file

@ -54,7 +54,7 @@ int main(void) {
char * nickname = map_getValue(config,"nickname");
if(nickname != NULL) {
strcpy(mynode.nick, nickname);
}
}else strcpy(mynode.nick, "");
char * port = map_getValue(config,"port");
if(port != NULL)

View file

@ -38,6 +38,7 @@ int peer_ConnetctTo(char* ip,int port,peerList* peerList, node_data my,fd_set* f
}
logger_log("Sent!Waiting for response...");
char buf[DEFAULT_BUFLEN];
ZeroMemory(buf,DEFAULT_BUFLEN);
int inBytes = recv(sock, buf, DEFAULT_BUFLEN, 0);
if (inBytes <= 0) {
logger_log("Error: Invalid response!");
@ -50,7 +51,6 @@ int peer_ConnetctTo(char* ip,int port,peerList* peerList, node_data my,fd_set* f
return -1;
}
map m = getHandshakeData(buf);
map_dump(m);
node_data node;
strcpy(node.ip,ip);
@ -89,6 +89,7 @@ int peer_ConnetctTo(char* ip,int port,peerList* peerList, node_data my,fd_set* f
logger_log("Error: Invalid response!Port not found in handshake.");
return -1;
}
ZeroMemory(node.nick,30);
char * nickname = map_getValue(m,"nickname");
if(nickname != NULL) {
strcpy(node.nick, nickname);
@ -133,7 +134,7 @@ int peer_HandleConnection(SOCKET listening,peerList *peerList, node_data my,fd_s
inet_ntop(AF_INET, &client.sin_addr, ip, NI_MAXHOST);
char buf[DEFAULT_BUFLEN];
ZeroMemory(buf,DEFAULT_BUFLEN);
int inBytes = recv(sock, buf, DEFAULT_BUFLEN, 0);
if (inBytes <= 0) {
closesocket(sock);
@ -147,7 +148,6 @@ int peer_HandleConnection(SOCKET listening,peerList *peerList, node_data my,fd_s
int len;
map m = getHandshakeData(buf);
map_dump(m);
node_data node;
strcpy(node.ip,ip);

View file

@ -246,8 +246,8 @@ void getIndex(char* folder,peerList list,char outputBuffer[]){
sprintf(content, "%s<li>"
"<a href=\"%s\">",
content, list.array[i].peerData.id);
if(strlen(list.array[i].peerData.nick) != 0){
sprintf(content, "%s%s - ",content,list.array[i].peerData.nick);
if(strcmp(list.array[i].peerData.nick,"") !=0){
sprintf(content, "%s%s %d- ",content,list.array[i].peerData.nick,strlen(list.array[i].peerData.nick));
}
sprintf(content,"%s%s</a></li>\n",content, list.array[i].peerData.id);
}