-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverService.c
131 lines (118 loc) · 2.54 KB
/
serverService.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "file.h"
char *_signin(char username[20], char password[20])
{
if (checkAccountExist(username) == 1)
{
account = getAccount(username);
if (account->status == 1)
{
if (checkPassword(username, password))
{
account->isLogin = 1;
account->loginTimeLeft = 3;
return ("Login successfully");
}
else
{
return ("Password is incorrect");
}
}
else
{
return ("Account is blocked");
}
}
else
{
return ("Cannot find account");
}
}
char *_signup(char username[20], char password[20])
{
if (checkAccountExist(username) == 1)
{
return ("Username is already exits");
}
else
{
addToLinkList(username, password, 1, 0, 0);
account = getAccount(username);
account->isLogin = 1;
account->loginTimeLeft = 3;
writeFile();
return ("Signup successfully");
}
}
char *_signout(char username[20])
{
if (checkAccountExist(username))
{
if (!strcmp(account->username, username))
{
account = NULL;
return ("Goodbye");
}
else
{
return ("This is not your username");
}
}
else
{
return ("Cannot find account");
}
}
char *_lockAccount(char username[20])
{
account = getAccount(username);
account->status = 0;
writeFile();
return ("Account is blocked");
}
char *_getRank(char name[])
{
rank *s1, *ranktemp;
node *temp;
char *sendRank = (char *)calloc(500, sizeof(char));
char *str;
int i = 1;
temp = first;
while (temp)
{
s1 = initRankList(s1, temp->username, temp->win, temp->lose);
temp = temp->next;
}
ranktemp = rankfirst;
while (ranktemp)
{
str = (char *)calloc(3, sizeof(char));
if (strcmp(name, ranktemp->username) == 0)
strcat(sendRank, "\033[1;33m");
sprintf(str, "%d", i);
strcat(sendRank, str);
strcat(sendRank, "\t");
strcat(sendRank, ranktemp->username);
strcat(sendRank, "\t");
str = (char *)calloc(3, sizeof(char));
sprintf(str, "%d", ranktemp->win);
strcat(sendRank, str);
strcat(sendRank, "\t");
str = (char *)calloc(3, sizeof(char));
sprintf(str, "%d", ranktemp->lose);
strcat(sendRank, str);
strcat(sendRank, "\t");
str = (char *)calloc(10, sizeof(char));
gcvt(ranktemp->wlradio, 10, str);
strcat(sendRank, str);
if (strcmp(name, ranktemp->username) == 0)
strcat(sendRank, "\033[0m");
strcat(sendRank, "\n");
i++;
ranktemp = ranktemp->next;
}
rankfirst = NULL;
return sendRank;
}