-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCmdMsg.java
111 lines (99 loc) · 2.44 KB
/
CmdMsg.java
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
import java.io.Serializable;
/**
* Object to contain command and messages
* @author Alex Lewtschuk, Kai Sorensen
*/
public class CmdMsg extends Object implements Serializable {
String cmd;
String msg;
String event;
/**
* Constructor
* @param command
* @param messsage
*/
public CmdMsg(String command, String messsage){
this.cmd = command;
this.msg = messsage;
}
// /**
// * Constructor for an event if we needed it
// * @param event
// */
// public CmdMsg(String event){
// this.msg = event;
// }
/**
* This updates the objects contents
* @param updateCmd
* @param updateMsg
*/
public void updateContents(String updateCmd, String updateMsg){
this.cmd = updateCmd;
this.msg = updateMsg;
}
/**
* Alows modification of nickname
* @param trimmedNick
*/
public void updateNickname(String trimmedNick){
this.msg = trimmedNick;
}
/**
* Gets the command part of the object
* @return
*/
public String getCommand(){
return cmd;
}
/**
* Gets the message part of the object
* @return
*/
public String getMessage(){
return msg;
}
/**
* Gets the possible event in the object
* @return
*/
public String getEvent(){
return msg;
}
@Override
public String toString(){
return "Object contains command: " + cmd + " argument: " + msg;
}
/**
* Checks if the nickncame in the object has invalid characters
* @param msg
* @return
*/
public boolean checkBadNickChars(String msg) {
final Character[] specialChars = {'\t', '\n', '/', '\\'};
if(msg == null || msg.isEmpty()){
return true;
}
for(int i = 0; i < specialChars.length; i++){
for(int j = 0; j < msg.length(); j++){
char c = msg.charAt(j);
if(c == specialChars[i]){
return true;
}
}
}
return false;
}
/**
* Checks if the first character is blank. Used as an edge case check
* @param msg
* @return
*/
public boolean firstNickCharIsSpace(String msg){
if(msg.startsWith(" ")){
System.out.println("The first character is a space. Please reenter your name\n");
return true;
}
return false;
}
}