Ejemplo n.º 1
0
    def test_AddNametoConnection(self):
        server=EchoGameServer(host,port,data_size,msghand,1)

        self.assertEqual(server.gameList.gamersUnnamedNumber(),0)
        self.assertEqual(server.gameList.gamersNamedNumber(),0)
        client=EchoGameClient(host,port,data_size,msghand)
        server.handle_connection()
        self.assertEqual(server.gameList.gamersUnnamedNumber(),1)
        self.assertEqual(server.gameList.gamersNamedNumber(),0)

        def eff():
            client.socketStatus=False
            return "Nick"

        sys.stdin.readline = MagicMock( side_effect =eff)
        client.sendName()
        ansS = server.handle_connection()
        self.assertEqual(ansS,2)

        client.socketStatus=True
        client.sendName()

        self.assertEqual(server.gameList.gamerName(server.gameList.broadcastedGamersSockets()[0]),"Nick")
        self.assertEqual(server.gameList.gamersUnnamedNumber(),0)
        self.assertEqual(server.gameList.gamersNamedNumber(),1)
Ejemplo n.º 2
0
    def test_DeinedConnection(self):
        server=EchoGameServer(host,port,data_size,msghand,0)

        client=EchoGameClient(host,port,data_size,msghand)
        ansS = server.handle_connection()
        self.assertEqual(ansS,-1)
        ansC = client.handle_connection()
        self.assertEqual(ansC,('S', '_error', '\\Game Server\\ There is too many players on serwer'))

        self.assertEqual(server.gameList.gamersUnnamedNumber(),0)
Ejemplo n.º 3
0
    def test_NewConnection(self):
        server=EchoGameServer(host,port,data_size,msghand,maxPlayers)

        client=EchoGameClient(host,port,data_size,msghand)
        ansS = server.handle_connection()
        self.assertEqual(ansS,1)
        ansC = client.handle_connection()
        self.assertEqual(ansC,('S', '_name_request', '\\Game Server\\ Send your name'))

        self.assertEqual(server.gameList.gamersUnnamedNumber(),1)
Ejemplo n.º 4
0
    def test_sendMessageFromServerToClient(self):

        server=EchoGameServer(host,port,data_size,msghand,1)
        client=EchoGameClient(host,port,data_size,msghand)
        server.handle_connection()
        def eff():
            client.socketStatus=False
            return "Nick"
        sys.stdin.readline = MagicMock( side_effect =eff)
        client.sendName()
        server.handle_connection()
        client.socketStatus=True
        client.sendName()

        server.sendMessage("_info","Message","Nick")
        ansC = client.handle_connection()
        self.assertEqual(ansC,('S', '_info', '\\Game Server\\ Message'))
Ejemplo n.º 5
0
from TickTackToo.TickTackToo import TickTackToo, getCoordinate
import random
import time
import sys


game = TickTackToo()

host = 'localhost'
port = 50015
data_size = 1024
maxPlayers=2
msghand = TTT_MessageHandler()

try:
    server=EchoGameServer(host,port,data_size,msghand,maxPlayers)
except OSError:
    print("Adress already in use")
    sys.exit()


while server.gamersNumber() <2:
    resp = server.handle_connection()
    if resp is tuple:
        server.sendMessage("_error","Waiting on more gamers", resp[1])

print("Start game")

time.sleep(0.1)
server.broadcast_data("_start","Starting the TickTackToo game!")
Ejemplo n.º 6
0
    def test_broadcast_data(self):
        server=EchoGameServer(host,port,data_size,msghand,3)
        client1=EchoGameClient(host,port,data_size,msghand)
        server.handle_connection()
        client2=EchoGameClient(host,port,data_size,msghand)
        server.handle_connection()

        def eff():
            client1.socketStatus=False
            return "Nick_1"
        sys.stdin.readline = MagicMock( side_effect = eff )
        client1.sendName()
        server.handle_connection()
        client1.socketStatus=True
        client1.sendName()

        def eff():
            client2.socketStatus=False
            return "Nick_2"
        sys.stdin.readline = MagicMock( side_effect = eff )
        client2.sendName()

        server.handle_connection()
        client2.socketStatus=True
        client2.sendName()
        ansC = client1.handle_connection()

        self.assertEqual(ansC,('S', '_info', '\\Game Server\\ Player <Nick_2> has joined the game'))

        server.broadcast_data("_info","Message")
        ansC = client1.handle_connection()
        self.assertEqual(ansC,('S', '_info', '\\Game Server\\ Message'))
        ansC = client2.handle_connection()
        self.assertEqual(ansC,('S', '_info', '\\Game Server\\ Message'))
Ejemplo n.º 7
0
 def test_serverPromt(self):
   server=EchoGameServer(host,port,data_size,msghand,1)
   self.assertEqual(server.serverPromt(),'\\Game Server\\ ')
Ejemplo n.º 8
0
from MoreOrLess.MOL import MOL
from Echo.MessageHandler import MessageHandler
from Echo.EchoServer import EchoGameServer
import time
import sys

mol = MOL(1,100)

host = 'localhost'
port = 50016
data_size = 1024
maxPlayers=2
msghand = MessageHandler()

try:
    server=EchoGameServer(host,port,data_size,msghand,maxPlayers)
except OSError:
    print("Adress already in use")
    sys.exit()


startMsg = "More Or Less Game: number can be found from %d to %d!"%(mol.minV,mol.maxV)

continueGame = True
while continueGame :
    ans = server.handle_connection(startMsg)
    if isinstance(ans,tuple):
        numGam, gamer, msgType, msgText = ans
    else:
        continue
    print("%d - %s - %s - %s"%(numGam, gamer, msgType, msgText))