-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWriter.js
69 lines (57 loc) · 2.15 KB
/
Writer.js
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
function greet(socket) {
socket.write("Hello and welcome to PandaChat!\n")
}
function askName(socket) {
socket.write("What would you like your username to be?? (2-15 characters)\n")
}
function notifyNameInvalid(socket) {
socket.write("Sorry, please try again.\n")
socket.write("The name you have provided is either taken or has failed validation.\n")
socket.write("Type the command /users to see a list of all taken usernames\n")
askName(socket)
}
function welcomeUser(socket, username) {
socket.write("Welcome " + username + "! You are amongst friends.\n")
socket.write("Start talking to the community! For a list of commands write /help\n")
}
function notifyRoomCreated(socket, roomName) {
socket.write("Room creation successful you can join the room by entering: /join " + roomName + "\n")
}
function notifyFailedRoomCreation(socket, roomName) {
socket.write("There is already a room with the name: " + roomName + "\n")
}
function notifyNoRooms(socket) {
socket.write("There are currently no rooms made.\n")
socket.write("To create a room, use the command /create followed by the room name\n")
socket.write("ex: /create myRoom\n")
}
function notifyDisplayingRooms(socket) {
socket.write("Now Displaying Rooms:\n")
}
function notifyRoomDetails(socket, roomName, roomUserCount) {
socket.write(roomName + " contains [" + roomUserCount + "]\n")
}
function displayUsernames(socket, sockets) {
socket.write("User(s) within this room:\n")
sockets.forEach(function(s) { socket.write("* " + s.username + "\n") })
}
function printName(socket, username) {
socket.write("* " + username + "\n")
}
function printCommands(socket, commands) {
commands.forEach(function(command) {socket.write("* " + command + "\n") })
}
module.exports = {
greet : greet,
askName : askName,
notifyNameInvalid : notifyNameInvalid,
welcomeUser : welcomeUser,
notifyRoomCreated : notifyRoomCreated,
notifyFailedRoomCreation : notifyFailedRoomCreation,
notifyNoRooms : notifyNoRooms,
notifyDisplayingRooms : notifyDisplayingRooms,
notifyRoomDetails : notifyRoomDetails,
displayUsernames : displayUsernames,
printName : printName,
printCommands : printCommands
}