-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
executable file
·88 lines (71 loc) · 3.11 KB
/
client.py
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
#Author: Mike Jacobi
#Test and Update: Xu Zhang
#Virtual Werewolf Game
#Collaborators: Roya Ensafi, Jed Crandall
#This is an example client for players to connect to the Mafia server
#Copyright (c) 2012 Mike Jacobi, Xu Zhang, Roya Ensafi, Jed Crandall
#This file is part of Virtual Werewolf Game.
#Virtual werewolf is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#Virtual werewolf is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with Virtual werewolf. If not, see <http://www.gnu.org/licenses/>.
import signal
import sys
import os
import pwd
import getpass
sys.path.append('/home/moderator/')
import communication as c
from threading import Thread
uid=pwd.getpwuid(os.getuid())[0].split('p')[1]
inPipe='sto'+uid
outPipe=uid+'tos'
def sayWolf():
c.send(getpass.getUser()+' MAYBE IS MAYBE MUCH WOLF - says the KGB',outPipe)
def sayWitch():
c.send(getpass.getUser()+' seems like maybe a wolf/human combo - says the KGB',outPipe)
def sayPerson():
c.send(getpass.getUser()+' could be? REGULAR HUMAN - says the KGB',outPipe)
def listen():
isListening=1
sendThread = Thread(target=send,args=[])
sendThread.setDaemon(True)
sendThread.start()
while isListening:
try: data=c.recv(inPipe)#receive data from moderator
except:continue
try:#process received data
# here we'd begin a non blocking timer which will send weird messages
import threading
if "YOU ARE A wolf" in data[2]:
timer = threading.Timer(20.0, sayWolf)
timer.start()
if "YOU ARE A witch" in data[2]:
timer = threading.Timer(20.0, sayWitch)
timer.start()
if "YOU ARE A wolf" in data[2]:
timer = threading.Timer(20.0, sayPerson)
timer.start()
if data[2]=="close":
print "Connection closed."
isListening=0
sendThread._Thread__stop()
exit()
else: print data[2]
except Exception, p: pass
#https://www.thegeekstuff.com/2013/02/stack-smashing-attacks-gcc/
def send():
c.send('connect',outPipe)
while 1:
try:
msg=raw_input()#listen for user input
c.send(msg,outPipe)
except: pass
if __name__=='__main__':
listen()