Example #1
0
 def __init__(self):
     self.new_clients = [
     ]  #list of new sockets of which the user id is not known
     self.logged_name2sock = {}  #dictionary mapping username to socket
     self.logged_sock2name = {}  # dict mapping socket to user name
     self.all_sockets = []
     self.group = grp.Group()
     self.players = p.Players()
     #start server
     self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.server.bind(SERVER)
     self.server.listen(5)
     self.all_sockets.append(self.server)
     #initialize past chat indices
     self.indices = {}
     # sonnet
     # self.sonnet_f = open('AllSonnets.txt.idx', 'rb')
     # self.sonnet = pkl.load(self.sonnet_f)
     # self.sonnet_f.close()
     self.sonnet = indexer.PIndex("AllSonnets.txt")
     self.gaming_players = []  #record the gaming players
     self.wolves = grp.Group()  #add the wolves to a seperate chat group
     self.wg = []
     self.dead = []
     self.newkilled = ''
     self.newpoisoned = ''
     self.poll = {}
     self.pollNumber = 0
     self.values = []
Example #2
0
    def __init__(self):
        self.new_clients = [
        ]  #list of new sockets of which the user id is not known
        self.logged_name2sock = {}  #dictionary mapping username to socket
        self.logged_sock2name = {}  # dict mapping socket to user name
        self.all_sockets = []
        self.group = grp.Group()
        self.group_key = 0

        #start server
        self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.server.bind(SERVER)
        self.server.listen(5)
        self.all_sockets.append(self.server)

        #initialize past chat indices
        self.indices = {}

        # sonnet
        self.sonnet_f = open('AllSonnets.txt.idx', 'rb')
        self.sonnet = pkl.load(self.sonnet_f)
        self.sonnet_f.close()

        # pass to the minesweeper game
        self.minesweeper_group = MinesweeperGroup()
        self.short = ''  # will be a class in Minesweeper
        self.starter = ''  # game starter
        self.board = ''  # game board
        self.rules = ''
        self.end_msg = ''
Example #3
0
 def __init__(self):
     self.new_clients = [
     ]  #list of new sockets of which the user id is not known
     self.logged_name2sock = {}  #dictionary mapping username to socket
     self.logged_sock2name = {}  # dict mapping socket to user name
     self.all_sockets = []
     self.group = grp.Group()
     #start server
     self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.server.bind(SERVER)
     self.server.listen(5)
     self.all_sockets.append(self.server)
     #initialize past chat indices
     self.indices = {}
     # sonnet
     self.sonnet_f = open('AllSonnets.txt.idx', 'rb')
     self.sonnet = pkl.load(self.sonnet_f)
     self.sonnet_f.close()
     # game
     self.name2sign = {}
     self.board = self.getNewBoard()
     self.board[3][3] = "X"
     self.board[3][4] = "0"
     self.board[4][3] = "0"
     self.board[4][4] = "X"
 def __init__(self):
     self.new_clients = [] #list of new sockets of which the user id is not known
     self.logged_name2sock = {} #dictionary mapping username to socket
     self.logged_sock2name = {} # dict mapping socket to user name
     self.all_sockets = []
     self.group = grp.Group()
     #start server
     self.server=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.server.bind(SERVER)
     self.server.listen(5)
     self.all_sockets.append(self.server)
     #initialize past chat indices
     self.indices={}
     # sonnet
     self.sonnet_f = open('AllSonnets.txt.idx', 'rb')
     self.sonnet = pkl.load(self.sonnet_f)
     self.sonnet_f.close()
     #following stores the data for game
     self.shuffled = False
     self.gameinfo = [] #dictionaries store info of the game players
     self.highest_bet = 200
     self.jackpot = 0
     self.name_list = []
     self.served_cards = []
     self.cards_count = 3
     self.player_count = 0
     self.bet = {}
Example #5
0
 def __init__(self):
     self.new_clients = [
     ]  #list of new sockets of which the user id is not known
     self.logged_name2sock = {}  #dictionary mapping username to socket
     self.logged_sock2name = {}  # dict mapping socket to user name
     self.all_sockets = []
     self.group = grp.Group()
     #start server
     self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.server.bind(SERVER)
     self.server.listen(5)
     self.all_sockets.append(self.server)
     #initialize past chat indices
     self.indices = {}
     # sonnet
     self.sonnet_f = open('AllSonnets.txt.idx', 'rb')
     self.sonnet = pkl.load(self.sonnet_f)
     self.sonnet_f.close()
     # game
     self.player1 = ""
     self.player2 = ""
     self.game = None
     self.lastsend1 = ''
     self.lastsend2 = ''
     self.ready = {}
     self.record = {1: 0, 2: 0}
     self.cheat = {1: 0, 2: 0}
     self.banker = None
     self.round = 1
Example #6
0
    def __init__(self):
        self.new_clients = []  # list of new sockets of which the user id is not known
        self.logged_name2sock = {}  # dictionary mapping username to socket
        self.logged_sock2name = {}  # dict mapping socket to user name
        self.all_sockets = []
        self.group = grp.Group()
        # start server
        self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.server.bind(SERVER)
        self.server.listen(5)
        self.all_sockets.append(self.server)
        # initialize past chat indices
        self.indices = {}
        # sonnet
        self.sonnet = indexer.PIndex("AllSonnets.txt")
        self.msgTime = []
#-------------------------------------------------------------
        self.gameGroup = grp.Group()
Example #7
0
    def __init__(self):
        self.new_clients = [
        ]  #list of new sockets of which the user id is not known
        self.logged_name2sock = {}  #dictionary mapping username to socket
        self.logged_sock2name = {}  # dict mapping socket to user name
        self.all_sockets = []
        self.group = grp.Group()
        #start server
        #==============================================================================
        #       SERVER SIDE TCP SOCKET NOTES
        #        Above is a TCP-socket, socket.AF_inet for family and socket.SOCK_STREAM for type
        #        The socket.Socket objects have the following main methods:
        #        1. bind("localhost", PORT_NUMBER): specific for server socket
        #        2. listen(1):
        #                -specific for server socket
        #        3. accept(): used to accept an incoming connection, will block
        #                      until a new client connects. When client connects, it will
        #                        create a new socket and return it together with the client's address
        #                -specific for server socket
        #        4. connect(): specific for client socket
        #        5. send():
        #                   -both types (server/client)
        #        6. recv(1024): example: socketA.recv(1024) will read data from socketA in batches of 1024 bytes
        #                   -both types (server/client)
        #        7. sendall(data): will send all data back to socketB.sendall(data) while repeatedly calling
        #                            the recv()  -  Ignore this for now.

        #       ALL socket methods block, meaning they do not let program do anything else when it
        #        is reading from a socket or writing to the program
        #
        #
        #       SERVER INFORMATION from chat_utils.py
        #
        #       CHAT_IP = socket.gethostname()
        #        CHAT_PORT = 1112
        #        SERVER = (CHAT_IP, CHAT_PORT)
        #
        #
        #
        #
        #
        #
        #
        #==============================================================================
        self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.server.bind(SERVER)
        self.server.listen(5)
        self.all_sockets.append(self.server)
        #initialize past chat indices
        self.indices = {}  #CHECK... is this meant to be an Index object?
        #sonnet indexing
        self.sonnet_f = open('AllSonnets.txt.idx', 'rb')
        self.sonnet = pkl.load(self.sonnet_f)
        self.sonnet_f.close()
Example #8
0
 def __init__(self):
     self.new_clients = [
     ]  #list of new sockets of which the user id is not known
     self.logged_name2sock = {}  #dictionary mapping username to socket
     self.logged_sock2name = {}  # dict mapping socket to user name
     self.all_sockets = []
     self.group = grp.Group()
     #start server
     self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.server.bind(SERVER)
     self.server.listen(
         15)  # the maximum num of clients connecting to the server
     self.all_sockets.append(self.server)
     #initialize past chat indices
     self.indices = {}
 def __init__(self):
     self.new_clients = [
     ]  # list of new sockets of which the user id is not known
     self.logged_name2sock = {}  # dictionary mapping username to socket
     self.logged_sock2name = {}  # dict mapping socket to user name
     self.all_sockets = []
     self.group = grp.Group()
     # start server
     self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.server.bind(SERVER)
     self.server.listen(5)
     self.all_sockets.append(self.server)
     # initialize past chat indices, TO store chat history.
     # indices will assigned later when there is user logged in
     self.indices = {}
     # sonnet
     self.sonnet = indexer.PIndex("AllSonnets.txt")
     self.play_once = None
Example #10
0
 def __init__(self):
     self.new_clients = [
     ]  # list of new sockets of which the user id is not known
     self.logged_name2sock = {}  # dictionary mapping username to socket
     self.logged_sock2name = {}  # dict mapping socket to user name
     self.all_sockets = []
     self.group = grp.Group()
     # start server
     self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.server.bind(SERVER)
     self.server.listen(5)
     self.all_sockets.append(self.server)
     # initialize past chat indices
     self.indices = {}
     # sonnet
     self.sonnet = indexer.PIndex("AllSonnets.txt")
     ### Diffie-Hellman Key Exchange ###
     self.base_key = 17837
     self.clock_key = 17977
    def __init__(self):
        self.current_remain = 0
        self.question_dic = 0
        self.answer_dic = 0
        self.count_player = 0
        self.player_list = []
        self.count = 0

        self.point = 0
        self.user = {"conqueror": [], "defendant": []}  #
        self.user_num = {
            "conqueror": 0,
            "defendant": 0
        }  #create a dictionary counting the users for each role, they can only be equal to enter the game
        self.level = 1
        self.new_clients = [
        ]  #list of new sockets of which the user id is not known
        self.logged_name2sock = {}  #dictionary mapping username to socket
        self.logged_sock2name = {}  # dict mapping socket to user name
        self.all_sockets = []
        self.group = grp.Group()
        #start server
        self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.server.bind(SERVER)
        self.server.listen(5)
        self.all_sockets.append(self.server)
        #initialize past chat indices
        self.indices = {}
        # sonnet
        self.sonnet_f = open('AllSonnets.txt.idx', 'rb')
        self.sonnet = pkl.load(self.sonnet_f)
        self.sonnet_f.close()
        self.total_points = 0
        self.timerInfo = {
            "time": -1,
            "to": "",
            "remain": 0,
            "question": 0,
            "activate": False
        }
        threading._start_new_thread(self.timerThread, ())
Example #12
0
    def __init__(self):
        self.new_clients = [
        ]  #list of new sockets of which the user id is not known
        self.logged_name2sock = {}  #dictionary mapping username to socket
        self.logged_sock2name = {}  # dict mapping socket to user name
        self.all_sockets = []
        self.group = grp.Group()
        self.group_key = 0

        #start server
        self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.server.bind(SERVER)
        self.server.listen(5)
        self.all_sockets.append(self.server)

        #initialize past chat indices
        self.indices = {}

        # sonnet
        self.sonnet_f = open('AllSonnets.txt.idx', 'rb')
        self.sonnet = pkl.load(self.sonnet_f)
        self.sonnet_f.close()

        # pass to the minesweeper game
        self.minesweeper_group = MinesweeperGroup()
        self.short = ''  # will be a class in Minesweeper
        self.starter = ''  # game starter
        self.board = ''  # game board
        self.rules = ''
        self.end_msg = ''

        # game leader board
        self.start_time = 0
        self.end_time = 0
        self.top_grp = []
        self.top_time = []
        self.leaderboard = {
            100000: ['testplayer1', 'testplayer2'],
            100020: ['testplayer3', 'testplayer4'],
            100010: ['testplayer5', 'testplayer6']
        }  #key: time period , value: grp members' names as a list
Example #13
0
 def __init__(self):
     self.new_clients = [] #list of new sockets of which the user id is not known
     self.logged_name2sock = {} #dictionary mapping username to socket
     self.logged_sock2name = {} # dict mapping socket to user name
     self.all_sockets = []
     self.group = grp.Group()
     #start server
     self.server=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.server.bind(SERVER)
     self.server.listen(5)
     self.all_sockets.append(self.server)
     #initialize past chat indices
     self.indices={}
     # sonnet
     self.sonnet_f = open('AllSonnets.txt.idx', 'rb')
     self.sonnet = pkl.load(self.sonnet_f)
     self.sonnet_f.close()
     #demo
     self.demo_f = open("demo.txt", "r")
     self.demo = self.demo_f.readlines()
     self.demo_f.close()
 def __init__(self):
     self.new_clients = [] #list of new sockets of which the user id is not known
     self.logged_name2sock = {} #dictionary mapping username to socket
     self.logged_sock2name = {} # dict mapping socket to user name
     self.all_sockets = []
     self.group = grp.Group()
     #tictactoe incorporation
     self.ttt = t.TicTacToe()
     #start server
     self.server=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.server.bind(SERVER)
     self.server.listen(5)
     self.all_sockets.append(self.server)
     #initialize past chat indices
     self.indices={}
     # sonnet
     # self.sonnet_f = open('AllSonnets.txt.idx', 'rb')
     # self.sonnet = pkl.load(self.sonnet_f)
     # self.sonnet_f.close()
     self.sonnet = indexer.PIndex("AllSonnets.txt")
     self.public_key1 = 71031
     self.public_key2 = 20573
Example #15
0
 def __init__(self):
     self.new_clients = [] #list of new sockets of which the user id is not known
     self.logged_name2sock = {} #dictionary mapping username to socket
     self.logged_sock2name = {} # dict mapping socket to user name
     self.all_sockets = []
     self.group = grp.Group()
     #start server
     self.server=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
     self.server.bind(SERVER)
     self.server.listen(5)
     self.all_sockets.append(self.server)
     #initialize past chat indices
     self.indices={}
     #sonnet indexing
     self.sonnet = indexer.PIndex("AllSonnets.txt")
     #render stuff
     self.conf     = None
     self.height   = None
     self.rendered = None
     self.starter  = None
     self.pieces   = None
Example #16
0
 def __init__(self):
     self.new_clients = [
     ]  # list of new sockets of which the user id is not known
     self.logged_name2sock = {}  # dictionary mapping username to socket
     self.logged_sock2name = {}  # dict mapping socket to user name
     self.all_sockets = []
     self.group = grp.Group()
     # start server
     self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.server.bind(SERVER)
     self.server.listen(5)
     self.all_sockets.append(self.server)
     # initialize past chat indices
     self.indices = {}
     # sonnet
     self.sonnet_f = open('AllSonnets.txt.idx', 'rb')
     self.sonnet = pkl.load(self.sonnet_f)
     self.sonnet_f.close()
     # game
     self.game = {}
     self.game_started = {}  # whether game is on
     self.who = PLAYER_BLACK  # whose turn # intend to make every turn uniform
     self.players = []  # unused for now, to be developed
Example #17
0
#!/usr/bin/env python3
import sys, os, socket, json, chat_group, time
from socketserver import ThreadingMixIn
from http.server import SimpleHTTPRequestHandler, HTTPServer
from random import *

HOST = socket.gethostname()
users = []
logged_msgs = {}
g = chat_group.Group()
codes = {
    '%20': ' ',
    '%22': '"',
    '%23': '#',
    '%24': '$',
    '%25': '%',
    '%26': '&'
}
activityLog = {}


class RequestHandler(SimpleHTTPRequestHandler):
    def do_POST(self):
        length = int(self.headers['Content-Length'])
        dat = self.rfile.read(length)
        data = self.dictize(dat)
        print(data)
        for x, y in data.items():
            print(x + ":" + y)
        if ('u-name' in data.keys()):
            self.do_UNAME(data['u-name'])