def Connect(self): self.lastConnect = time() connection.DoConnect((self.parent.serverhost, 31415)) packet = {"action": "playerid", "version": VERSION} if self.playerID: packet.update({"id": self.playerID}) self.Send(packet)
def main(): connection.DoConnect(('localhost', 9126)) #connection.Send({"action": "Login", "name": "anonymous", "password":""}) eng = engine chatbox = chat.ChatBox() """ numbers on end for priority where '0' is highest (namely of drawing) presently only have 3 layers. Easy to add more, you'll see how if you want. """ eng.AddObject('mouse', mouse, 0) #mouse needs to be first or things look funny.. eng.AddObject('con. wrapper', ConnectionWrapper(), 1) eng.AddObject('map engine', mapEngine, 2) eng.AddObject('window manager', windowManager, 1) AddTestWindows() ##take me out later eng.MainLoop()
def RunClient(): # Comment out changes that are not compatible with server currently on host (= getting game from Server) if getattr(sys, 'frozen', False): os.chdir(sys._MEIPASS) """This is the launch point for the client. It sets up the various classes and starts the game loop. Steps -- (i) player provides host:port info, and connection to server established. (ii) clientState initialized (iii) controller initialized (iv) ruleset imported << this is section that I edited for this. Labeled changes: # oldServer. (v) player provides name (vi) game window created (vii) tableView and handView initialized (viii) playername confirmed with server and player_index found. (ix) main game loop """ # (i) Connect to server: host = str(input("Enter the host [xxxxx.net] ") or "xxxxx.net") port = str(input("Enter the port[8080] ") or "8080") connection.DoConnect((host, int(port))) # (ii)-(iv) initialize clientState and gameControl. Will get name of game from server ruleset = "tbd" # ruleset will be obtained from server. If wish to run in test mode than change "tbd" to "test" # oldServer - added next line and commented out gameControl.askForGame() ruleset = str( input("Enter the game - Liverpool or HandAndFoot [HandAndFoot]") or "HandAndFoot") clientState = ClientState(ruleset) gameControl = Controller(clientState) # gameControl.askForGame() # Ask server for name of game to be played. while clientState.ruleset == "tbd": connection.Pump() gameControl.Pump() sleep(0.001) clientState.importRules( clientState.ruleset ) # Have rec'd ruleset name from server, so import the rules. # gameControl.setName( ) # Ask the player their name, and confirm it is acceptable. playername = gameControl.getName() # Confirm server has player name. gameboard = CreateDisplay(playername) tableView = TableView(gameboard.display, clientState.ruleset) handView = HandView(gameControl, gameboard.display, clientState.ruleset) current_round = handView.round_index while (len(tableView.player_names) < 1) or (tableView.player_names.count('guest') > 0): # Note that if two people join with the same name almost simultaneously, then both might be renamed. gameboard.refresh() connection.Pump() gameControl.Pump() tableView.Pump() tableView.playerByPlayer(current_round) note = "Waiting for all current players to pick legit names. If wait seems too long, " \ "then it is possible you have the wrong server or port#..." gameboard.render(note) sleep(0.01) playername = gameControl.checkNames(tableView.player_names) # games with Shared_Board=True need player_index, first must insure that server is reporting correct name. # This can take a few cycles. if clientState.rules.Shared_Board: clientState.player_index = -99 while clientState.player_index == -99: try: clientState.player_index = tableView.player_names.index( playername) except Exception as err: note = "{0} waiting for name in player_names to update...".format( err) gameboard.refresh() connection.Pump() gameControl.Pump() tableView.Pump() tableView.playerByPlayer(current_round) gameboard.render(note) sleep(0.001) while True: # Primary game loop. this_round = handView.round_index gameboard.refresh() handView.nextEvent() connection.Pump() gameControl.Pump() tableView.Pump() tableView.playerByPlayer(this_round) if clientState.rules.Shared_Board: player_index = tableView.player_names.index(playername) visible_scards = tableView.visible_scards handView.update(player_index, len(tableView.player_names), visible_scards) else: handView.update() note = gameControl.note gameboard.render(note) sleep(0.001)
from PodSixNet.Connection import connection # connect to the server - optionally pass hostname and port like: ("mccormick.cx", 31425) connection.DoConnect() connection.Send({"action": "myaction", "blah": 123, "things": [3, 4, 3, 4, 7]}) connection.Pump()