32
32
33
33
# custom say hello command
34
34
def log (message ):
35
+ timestamp = str (strftime ("[%d %b %Y - %H:%M:%S]" , gmtime ()))
35
36
f = open ("Logs/chat_log_" + dateString + ".txt" ,"a+" )
36
- f .write (message )
37
+ f .write (timestamp + " " + message + " \n " )
37
38
f .close ()
38
39
def getTimestamp ():
39
40
time = strftime ("[%H:%M:%S]" , gmtime ())
@@ -99,7 +100,8 @@ def stripHash(data):
99
100
date = strftime ("%a_%d_%b_%Y" , gmtime ())
100
101
dateString = str (date )
101
102
print ("Server started." )
102
- log ("Server started at " + timestamp + "\n " )
103
+ log ("\n \n -----------------------------------------" + "Server started at " + str (strftime ("[%d %b %Y - %H:%M:%S]" , gmtime ()))
104
+ + "-----------------------------------------" )
103
105
104
106
def parseInput (data , con ):
105
107
global buffer
@@ -134,11 +136,8 @@ def parseInput(data, con):
134
136
con .send (hashData ('<close>' ))
135
137
if usernameTaken == 0 :
136
138
clients [newclient ] = con
137
- timestamp = getTimestamp ()
138
- date = strftime ("%a_%d_%b_%Y" , gmtime ())
139
- dateString = str (date )
140
139
messageAll (hashData (messageInfo ("[ANNOUNCEMENT] New client " + newclient + " connected. Welcome to \' " + getChatName ()+ "\' !" )))
141
- log ("New client " + newclient + " at " + getTimestamp () + " \n " )
140
+ log ("New client \' " + newclient + "\' connected " )
142
141
143
142
elif "<changenickname " in data : #<changenick Daniel>
144
143
oldnick = getClientName (con )
@@ -148,12 +147,8 @@ def parseInput(data, con):
148
147
newnick = splitMessage [1 ]
149
148
del clients [getClientName (con )] #Removes client value
150
149
clients [newnick ] = con # Adds a client value based on new nickname
151
- timestamp = getTimestamp ()
152
- date = strftime ("%a_%d_%b_%Y" , gmtime ())
153
- dateString = str (date )
154
- log ("Nickname changed to " + newnick + " By " + oldnick + " at " + timestamp + "\n " )
155
-
156
- messageAll (hashData (messageInfo (oldnick + " has changed their nickname to \' " + newnick + "\' ." )))
150
+ log ("Nickname changed to " + newnick + " By " + oldnick )
151
+ messageAll (hashData (messageInfo (oldnick + " has changed their nickname to \' " + newnick + "\' " )))
157
152
elif "<chat>" in data : # <msg>Daniel~This is a message</msg>
158
153
timestamp = getTimestamp ()
159
154
tagless = data [6 :- 7 ]
@@ -162,23 +157,14 @@ def parseInput(data, con):
162
157
user = splitMessage [0 ]
163
158
message = splitMessage [1 ]
164
159
print ("Message received" )
165
- date = strftime ("%a_%d_%b_%Y" , gmtime ())
166
- dateString = str (date )
167
- log ("Message : " + timestamp + " " + user + ": " + message + "\n " )
160
+ log ("Message : " + user + ": " + message )
168
161
messageAll (hashData (messageMsg (timestamp + " " + user + ": " + message )))
169
162
elif "<ping>" in data :
170
- timestamp = getTimestamp ()
171
- date = strftime ("%a_%d_%b_%Y" , gmtime ())
172
- dateString = str (date )
173
- log ("Server pinged at " + timestamp + "\n " )
174
-
175
163
con .send (hashData ("<pong>" ))
164
+ log ("Server pinged by " + getClientName (con ))
176
165
elif "<connected>" in data :
177
- timestamp = getTimestamp ()
178
- date = strftime ("%a_%d_%b_%Y" , gmtime ())
179
- dateString = str (date )
180
- log ("Connection list called at " + timestamp + " List Value " + getClientList () + "\n " )
181
166
con .send (hashData (messageInfo (getClientList ())))
167
+ log ("Connection list called. " + getClientList ())
182
168
elif "<kick " in data :
183
169
kicker = getClientName (con )
184
170
tagless = data [1 :- 1 ]
@@ -188,13 +174,11 @@ def parseInput(data, con):
188
174
usercon = getClientCon (user )
189
175
usercon .send (hashData (messageInfo ("[ANNOUNCEMENT] You have been kicked by " + kicker + "." )))
190
176
usercon .send ('<close>' )
191
- timestamp = getTimestamp ()
192
- date = strftime ("%a_%d_%b_%Y" , gmtime ())
193
- dateString = str (date )
194
- log (user + " Kicked from Chat at " + timestamp + " by " + kicker + "\n " )
195
177
messageAll (hashData (messageInfo ("[ANNOUNCEMENT] \' " + user + "\' has been kicked from the chat by \' " + kicker + "\' ." )))
196
178
del clients [user ]
197
179
currentConnections .remove (usercon )
180
+ log (user + " has been kicked from the chat by " + kicker )
181
+
198
182
elif "<messages>" in data :
199
183
con .send (hashData (messageInfo ("Message count: " + str (getMessageCount ()))))
200
184
elif "<roomname>" in data :
@@ -204,11 +188,9 @@ def parseInput(data, con):
204
188
user = getClientName (con )
205
189
newname = data [16 :- 1 ]
206
190
setChatName (newname )
207
- timestamp = getTimestamp ()
208
- date = strftime ("%a_%d_%b_%Y" , gmtime ())
209
- dateString = str (date )
210
- log ("Chat Room name changed to " + newname + " at " + timestamp + "\n " )
211
191
messageAll (hashData (messageInfo ("[ANNOUNCEMENT] The room name has been changed from \' " + oldname + "\' to \' " + newname + "\' by " + user + "." )))
192
+ log ("Chat room name changed from " + oldname + " to " + newname + " by " + user )
193
+
212
194
else :
213
195
if debug == 1 :
214
196
print ("[DEBUG] Hashes do not match!" )
0 commit comments