-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.d.ts
188 lines (173 loc) · 4.61 KB
/
types.d.ts
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
export type DirectMessageChannel = {
/** The username of the person that initiated the DM channel. */
initiatedBy: string;
/** The username of the user the DM channel is with. */
receiver: string;
/** The list of messages in the DM channel. */
messages: Message[];
}
export type Message = {
from: string;
content: string;
timestamp: number;
read: boolean;
}
export type KeysFile = {
G_CLIENT_ID: string;
VAPID: {
SUBJECT: string;
PUBLIC_KEY: string;
PRIVATE_KEY: string;
};
JWT_SECRET: string;
}
export type ChatLog = {
username: string;
realName: string;
message: string;
}
export type UserLoginRes = {
success: true;
status: 200;
token: string;
} | {
success: false;
status: number;
message: string;
}
/** Player only used for single game. */
export type Player = {
/** Name chosen at game start. */
gameName: string;
/** Name on google account. */
realName: string;
/** Username based on realName. */
username: string;
score: number;
ready: boolean;
freeSpin: boolean;
alive: boolean;
move: Move;
lastMove: LastMove;
/** Number of times a player has not made a move in the given time. */
strikes: number;
}
export type Move = "freeSpin" | "higher" | "lower" | "none" | "bank";
type LastMove = Move | "stillOut" | "";
export type PlayerKeys = {
[key: string]: string;
}
export type GameTimers = {
start: NodeJS.Timeout | null;
play: NodeJS.Timeout | null;
};
export type Game = {
numbersLeft: number[];
thisSpin: number;
lastSpin: number;
started: boolean;
spinNumber: number;
/** Points accumulated this round. */
points: number;
result: "higher" | "lower" | "none";
round: number;
/** Wether or not players can join the game right now. */
canJoin: boolean;
/** Winner of last game. */
lastWinner: string;
};
/** Data about the game. */
export type GameData = {
playerList: string[];
players: Player[];
game: Game;
rankings: Ranking[]
};
/** Data that is sent to clients about the game plus extra information. */
export type SendData = GameData & {
/** In game chat */
chat: string[];
/** Whether game specific data is being live updated. (false when guessing is occuring) */
live: boolean;
/** Version */
version: string;
/** Information about the user. */
me: {
name: string;
username: string
friendRequests: string[];
friends: string[];
blockedUsers: string[];
directMessageChannels: DirectMessageChannel[];
silent: boolean;
acceptingFriendRequests: boolean;
};
}
export type Ranking = {
name: string;
score: number;
wins: number;
}
/** Return value for joinGame function. */
export type JoinGameRes = {
status: "error";
msg: string;
} | {
status: "success";
key: string;
}
/** A key value pair of users to the last time they send a request. */
export type LastOnline = {
[key: string]: number;
}
/** The object that is sent in a post request. */
export type PostObject = {
action: "join";
name: string;
} | {
action: "chat";
message: string;
} | {
action: "handleFriend";
/** The friend to handle. */
username: string;
accept: boolean;
} | {
action: "silentToggle";
mode: boolean;
} | {
action: "acceptRequestsToggle";
mode: boolean;
} | {
action: "unblock";
/** The friend to unblock. */
username: string;
} | {
action: "addFriend";
/** The friend to add. */
username: string;
} | {
action: "messageFriend";
username: string;
message: string;
} | {
action: "readMessages";
/** The friend of the messages that are being read. */
friend: string;
/** Total number of messages minus the indices of the messages. */
messageReverseIndices: number[];
} | {
action: "inviteFriend";
username: string;
} | {
action: "start";
name: string;
} | {
action: "play";
name: string;
move: Move;
} | {
action: "chatInGame";
name: string;
message: string;
}