def _getmaps(self, noask=None): if not self.maps: maplst = self.gameini if len(self.servers[self.srv]) > 1: maplst = self.servers[self.srv][1] if maplst.startswith('~'): maplst = expanduser(maplst) if not maplst.startswith('/'): print( 'error: cannot read maplist if no absolute path is provided' ) with open(maplst, 'r') as mfh: lines = mfh.readlines() try: with open(expanduser(self.maptbl), 'r') as mfh: self.mapnames = yload(mfh.read(), Loader=Loader) except FileNotFoundError: with open(expanduser(self.maptbl), 'w+') as mfh: mfh.write(ydump({}, Dumper=Dumper)) self.mapnames = {} for l in lines: if not l or not l.startswith('MapRotation'): continue ugcid = l.split('MapId="')[1].split('", ')[0] gmmod = l.split('GameMode="')[1].split('")')[0] name = self._getmapname(ugcid) self.maps[name] = [ugcid, gmmod] self.mapnames[ugcid] = name with open(expanduser(self.maptbl), 'w+') as mfh: mfh.write(ydump(self.mapnames, Dumper=Dumper)) if noask: return ask = [ iList( 'map', carousel=True, message='select map', choices=[m for m in self.maps.keys()] + ['<Return>'], ), ] mapp = list(prompt(ask).values())[0] if mapp == '<Return>': return mmod = self.maps[mapp][1] modes = [mmod] + [s for s in ['SND', 'TDM', 'DM', 'GUN'] if s != mmod] ask = [ iList( 'mod', carousel=True, message='select mode (irrelevant if set by map)', choices=[m for m in modes] + ['<Return>'], ), ] mode = list(prompt(ask).values())[0] if mode != '<Return>': return '%s %s' % (self.maps[mapp][0], mode)
def _getammotype(self): ask = [ iList( 'ammo', carousel=True, message='select ammo-limit', choices=[0, 1, 2, '<Return>'], ), ] ammo = list(prompt(ask).values())[0] if ammo != '<Return>': return ammo
def _getteam(self): ask = [ iList( 'team', carousel=True, message='select team', choices=[ "Blue Team (Defenders)", "Red Team (Attackers)", '<Return>' ], ), ] team = list(prompt(ask).values())[0] if team != '<Return>': return team
def _getitem(self): with open(self.itemtbl, 'r') as ifh: items = [l.split(',')[0] for l in ifh.readlines()] ask = [ iList( 'item', carousel=True, message='select item', choices=items + ['<Return>'], ), ] item = list(prompt(ask).values())[0] if item != '<Return>': return item
def _getskin(self): ask = [ iList( 'skin', carousel=True, message='select skin', choices=[ 'clown', 'prisoner', 'naked', 'farmer', 'russian', 'nato', '<Return>' ], ), ] skin = list(prompt(ask).values())[0] if skin != '<Return>': return skin
def _getsteamid(self, cmd): userids = self._players() if not userids: print('\nerror: executing "%s" is impossible - no players\n' % cmd) return ask = [ iList( 'user', carousel=True, message='select user to %s' % cmd, choices=list(userids.keys()) + ['<Return>'], ), ] usr = list(prompt(ask).values())[0] if usr == '<Return>': return return userids[usr]
def _login(self): """server login method""" ask = [ iList( 'srv', carousel=True, message='select server', choices=[s for s in self.servers.keys()] + ['<Exit>'], ), ] srv = list(prompt(ask).values())[0] if srv == '<Exit>': exit() passwd = self.servers[srv][0] if len(self.servers[srv]) > 1: maplist = self.servers[srv][1] server, port = srv.split(':') self.socket.connect((server, int(port))) self._send('') print(self._send(passwd)) return srv
def _cmdselects(self): noargs = [ 'Info', 'ResetSND', 'RefreshList', 'RotateMap', 'ServerInfo', 'Help', '<Disconnect>' ] steams = ['Kick', 'Ban', 'Unban', 'InspectPlayer'] others = [ 'SwitchMap', 'SwitchTeam', 'GiveItem', 'GiveCash', 'GiveTeamCash', 'SetPlayerSkin', 'SetLimitedAmmoType' ] order = [ 'Info', 'SwitchMap', 'RotateMap', 'ResetSND', 'Kick', 'Ban', 'Unban', 'InspectPlayer', 'GiveItem', 'GiveCash', 'GiveTeamCash', 'SetPlayerSkin', 'SetLimitedAmmoType', 'RefreshList', 'ServerInfo', '<Disconnect>' ] hlp = self.hlp['Help'] hlp = [h.split(' ')[0] for h in hlp.split(', ') if h.split(' ')[0]] + ['Info'] ask = [ iList( 'cmd', carousel=True, message='select command', choices=[o for o in order if o.strip('<>') in hlp], ), ] cmd = list(prompt(ask).values())[0].strip() if cmd in noargs: return cmd elif cmd in steams: sid = self._getsteamid(cmd) if not sid: return return '%s %s' % (cmd, sid) elif cmd in others: if cmd == 'SwitchMap': mapmod = self._getmaps() if not mapmod: return return 'SwitchMap %s' % mapmod elif cmd == 'SwitchTeam': sid = self._getsteamid(cmd) if not sid: return return 'SwitchTeam %s %s' % (sid, self._getteam()) elif cmd == 'GiveItem': sid = self._getsteamid(cmd) if not sid: return return 'GiveItem %s %s' % (sid, self._getitem()) elif cmd == 'GiveCash': sid = self._getsteamid(cmd) if not sid: return return 'GiveCash %s %s' % (sid, self._getcash()) elif cmd == 'GiveTeamCash': team = self._getteam() if not team: return return 'GiveTeamCash %s %s' % (team, self._getcash()) elif cmd == 'SetPlayerSkin': sid = self._getsteamid(cmd) if not sid: return return 'SetPlayerSkin %s %s' % (sid, self._getskin()) elif cmd == 'SetLimitedAmmoType': ammo = self._getammotype() if not ammo: return return 'SetLimitedAmmoType %s' % ammo