def call_from_console(self): global profile if profile is None: profile = cProfile.Profile() profile.enable() SMPacket = packetFactory.SystemMessagePacket( "[Proxy Notice] Profiling mode has been enabled, expect lag while this runs.", 0x0).build() for client in data.clients.connectedClients.values(): if client.get_handle() is not None: client.get_handle().send_crypto_packet(SMPacket) return "[Profiling] Profiling has been enabled." else: profile.disable() out = open( "profile_%s.txt" % calendar.timegm(datetime.datetime.utcnow().utctimetuple()), 'w') sort_by = 'cumulative' ps = pstats.Stats(profile, stream=out).sort_stats(sort_by) ps.print_stats() shutil.copy(out.name, "latest_profile.txt") out.close() profile = None SMPacket = packetFactory.SystemMessagePacket( "[Proxy Notice] Profiling mode has been disabled, any lag caused by this should subside.", 0x0).build() for client in data.clients.connectedClients.values(): if client.get_handle() is not None: client.get_handle().send_crypto_packet(SMPacket) return "[Profiling] Profiling has been disabled, results written to disk."
def call_from_client(self, client): idsega = client.myUsername if idsega is None or str(idsega) == "None" or idsega == "None": client.send_crypto_packet( packetFactory.SystemMessagePacket( "[Command] Tidak dapat menggunakan perintah ini dikarenakan anda adalah (Someone) atau (None) user.", 0x3).build()) else: preferences = dataclients.ClientPreferences(idsega) if preferences.has_preference( "chatMuted") and preferences.get_preference('chatMuted'): client.send_crypto_packet( packetFactory.SystemMessagePacket( "{yel}[PCP Bot] {red}Gchat anda berstatus: {gre}OFF {red}sehingga tidak dapat menggunakan Gchat.", 0x3).build()) return if preferences.has_preference("globalChatDirect"): isActive = preferences.get_preference("globalChatDirect") else: isActive = True #reverse mode isActive = not isActive preferences.set_preference("globalChatDirect", isActive) if isActive: client.send_crypto_packet( packetFactory.SystemMessagePacket( "{yel}[PCP Bot] {gre}Direct Global Chat diaktifkan. {red}PERHATIAN !!! {gre}Chat apapun baik AUTOWORD maupun yang kamu kirim ke Area/Party/Team akan auto send ke Global Chat !", 0x3).build()) else: client.send_crypto_packet( packetFactory.SystemMessagePacket( "{yel}[PCP Bot] {gre}Direct Global Chat dinonaktifkan.", 0x3).build())
def check_config(user): global ircMode if user.playerId in data.clients.connectedClients: client_preferences = data.clients.connectedClients[ user.playerId].preferences if not client_preferences.has_preference("globalChat"): client_preferences.set_preference("globalChat", True) if not client_preferences.has_preference("globalChatPrefix"): client_preferences.set_preference("globalChatPrefix", gchatSettings['prefix']) if client_preferences.get_preference('globalChat'): user.send_crypto_packet( packetFactory.SystemMessagePacket( "{yel}Use %sg <Message> to chat in Global. Respect and don't flood." % (config.globalConfig.get_key('commandPrefix')), 0x3).build()) else: user.send_crypto_packet( packetFactory.SystemMessagePacket( "{yel}Global chat is disabled. Use %sgon to enable it, %sg <Message> to chat, and %sgmode to toggle team/system chat mode." % (config.globalConfig.get_key('commandPrefix'), config.globalConfig.get_key('commandPrefix'), config.globalConfig.get_key('commandPrefix')), 0x3).build()) if not client_preferences.has_preference("gchatMode"): client_preferences['gchatMode'] = -1
def call_from_client(self, client): args = self.args.split(' ') if len(args) < 2: client.send_crypto_packet( packetFactory.SystemMessagePacket( "[Command] {red}Invalid usage.\n(Usage: %skick <PlayerID>)" % config.globalConfig.get_key('commandPrefix'), 0x3).build()) return if int(args[1]) in data.clients.connectedClients: if data.clients.connectedClients[int( args[1])].get_handle() is not None: data.clients.connectedClients[int(args[1])].get_handle( ).send_crypto_packet( packetFactory.SystemMessagePacket( "[Proxy] {yel}You have been disconnected from the proxy by an admin.", 0x2).build()) data.clients.connectedClients[int( args[1])].get_handle().transport.loseConnection() client.send_crypto_packet( packetFactory.SystemMessagePacket( "[Command] {gre}%s has been disconnected." % args[1], 0x3).build()) else: return "[Command] {red}%s could not be found." % args[1] else: client.send_crypto_packet( packetFactory.SystemMessagePacket( "[Command] {red}%s could not be found." % args[1], 0x3).build())
def call_from_client(self, client): """ :param client: ShipProxy.ShipProxy """ if len(self.args.split(" ", 1)) < 2: client.send_crypto_packet( packetFactory.SystemMessagePacket( "[Command] {red}Invalid usage. gunmute <Player Name>"). build()) return user_to_mute = self.args.split(" ", 1)[1] for player_id, player_data in data.players.playerList.iteritems(): if player_data[0].rstrip("\0") == user_to_mute: if player_id in data.clients.connectedClients: data.clients.connectedClients[player_id].preferences[ 'chatMuted'] = False client.send_crypto_packet( packetFactory.SystemMessagePacket( "[Command] {gre}Unmuted %s." % player_data[0].rstrip("\0"), 0x3).build()) else: client.send_crypto_packet( packetFactory.SystemMessagePacket( "[Command] {red}%s either is not connected or is not part of the proxy." % player_data[0].rstrip("\0"), 0x3).build())
def call_from_client(self, client): if client.playerId is not None: client_preferences = data.clients.connectedClients[ client.playerId].preferences if client_preferences['gchatMode'] == -1: client_preferences['gchatMode'] = 0 client.send_crypto_packet( packetFactory.SystemMessagePacket( "[Command] {gre}Global chat will now come through team chat.", 0x3).build()) elif client_preferences['gchatMode'] == 0: client_preferences['gchatMode'] = 1 client.send_crypto_packet( packetFactory.SystemMessagePacket( "[Command] {gre}Global chat will now come through system chat.", 0x3).build()) elif client_preferences['gchatMode'] == 1: client_preferences['gchatMode'] = -1 if gchatSettings['displayMode'] == 0: client.send_crypto_packet( packetFactory.SystemMessagePacket( "[Command] {gre}Global chat will now come through team chat. (Default)", 0x3).build()) else: client.send_crypto_packet( packetFactory.SystemMessagePacket( "[Command] {gre}Global chat will now come through system chat. (Default)", 0x3).build())
def doRedisGchat(message): gchatMsg = json.loads(message['data']) fb = ("G-%02i") % gchatMsg['ship'] shipl = ShipLabel.get(fb, fb) strgchatmsg = str(gchatMsg['text'].encode('utf-8')) if not check_irc_with_pso2(strgchatmsg): return if gchatMsg['server'] == PSO2PDConnector.connector_conf['server_name']: return if gchatMsg['sender'] == 1: for client in data.clients.connectedClients.values(): if client.preferences.get_preference('globalChat') and client.get_handle() is not None: if lookup_gchatmode(client.preferences) == 0: client.get_handle().send_crypto_packet(packetFactory.TeamChatPacket(gchatMsg['playerId'], "[GIRC] %s" % gchatMsg['playerName'], "[GIRC] %s" % gchatMsg['playerName'], "%s%s" % (client.preferences.get_preference('globalChatPrefix'), replace_irc_with_pso2(strgchatmsg).decode('utf-8'))).build()) else: client.get_handle().send_crypto_packet(packetFactory.SystemMessagePacket("[GIRC] <%s> %s" % (gchatMsg['playerName'], "%s%s" % (client.preferences.get_preference('globalChatPrefix'), replace_irc_with_pso2(strgchatmsg).decode('utf-8'))), 0x3).build()) else: if ircMode: global ircBot if ircBot is not None: ircBot.send_global_message(gchatMsg['ship'], str(gchatMsg['playerName'].encode('utf-8')), strgchatmsg, str(gchatMsg['server'])) for client_data in data.clients.connectedClients.values(): if client_data.preferences.get_preference('globalChat') and client_data.get_handle() is not None: if lookup_gchatmode(client_data.preferences) == 0: client_data.get_handle().send_crypto_packet(packetFactory.TeamChatPacket(gchatMsg['playerId'], "(%s) [%s] %s" % (gchatMsg['server'], shipl, gchatMsg['playerName']), gchatMsg['playerName'], "%s%s" % (client_data.preferences.get_preference('globalChatPrefix'), gchatMsg['text'])).build()) else: client_data.get_handle().send_crypto_packet(packetFactory.SystemMessagePacket("(%s) [%s] <%s> %s" % (gchatMsg['server'], shipl, gchatMsg['playerName'], "%s%s" % (client_data.preferences.get_preference('globalChatPrefix'), gchatMsg['text'])), 0x3).build())
def call_from_client(self, client): preferences = data.clients.connectedClients[client.playerId].preferences if preferences["globalChat"]: preferences['globalChat'] = False client.send_crypto_packet(packetFactory.SystemMessagePacket("[GlobalChat] Global chat has been disabled for you.", 0x3).build()) else: client.send_crypto_packet(packetFactory.SystemMessagePacket("[GlobalChat] You already have global chat disabled.", 0x3).build())
def check_config(user): global ircMode if user.playerId in data.clients.connectedClients: client_preferences = data.clients.connectedClients[user.playerId].preferences if not client_preferences.has_preference("globalChat"): client_preferences.set_preference("globalChat", True) if not client_preferences.has_preference("globalChatPrefix"): client_preferences.set_preference("globalChatPrefix", gchatSettings['prefix']) if client_preferences.get_preference('globalChat'): user.send_crypto_packet( packetFactory.SystemMessagePacket( "[Proxy] {0}Global chat is enabled. Use {1}g <Message> " "to chat, {1}goff to disable it, and {1}gmode to toggle " "team/system chat mode.".format( "{yel}", config.globalConfig['commandPrefix'] ), 0x3 ).build() ) else: user.send_crypto_packet(packetFactory.SystemMessagePacket( "[Proxy] {0}Global chat is disabled. Use {1}gon to enable it," " {1}g <Message> to chat, and {1}gmode to toggle team/system " "chat mode.".format( "{yel}", config.globalConfig['commandPrefix'] ), 0x3 ).build()) if not client_preferences.has_preference("gchatMode"): client_preferences['gchatMode'] = -1
def call_from_client(self, client): ship = clients.get_ship_from_port(client.transport.getHost().port) - 1 if data_eq[ship] and not check_if_EQ_old(ship): SMPacket = packetFactory.SystemMessagePacket("[Proxy] Incoming EQ Report from PSO2es: %s" % (msg_eq[ship]), 0x0).build() else: SMPacket = packetFactory.SystemMessagePacket("[Proxy] No new EQ Report from PSO2es", 0x0).build() client.send_crypto_packet(SMPacket)
def call_from_client(self, client): if client.playerId in data.clients.connectedClients: user_prefs = data.clients.connectedClients[client.playerId].preferences user_prefs.set_preference('translate_out', not user_prefs.get_preference('translate_out')) if user_prefs.get_preference('translate_out'): client.send_crypto_packet(packetFactory.SystemMessagePacket("[Translate] Enabled outgoing chat translation.", 0x3).build()) else: client.send_crypto_packet(packetFactory.SystemMessagePacket("[Translate] Disabled outgoing chat translation.", 0x3).build())
def call_from_client(self, client): if client.playerId in clients.connectedClients: user_prefs = clients.connectedClients[client.playerId].preferences user_prefs.set_preference('eqnotice', not user_prefs.get_preference('eqnotice')) if user_prefs.get_preference('eqnotice'): client.send_crypto_packet(packetFactory.SystemMessagePacket("[EQ Notice] Enabled EQ notices.", 0x3).build()) else: client.send_crypto_packet(packetFactory.SystemMessagePacket("[EQ Notice] Disabled EQ notices.", 0x3).build())
def call_from_client(self, client): client_preferences = clients.connectedClients[client.playerId].preferences ship = (client_preferences.get_preference('eqnotice_ship') - 1) if data_eq[ship] and not check_if_EQ_old(ship): SMPacket = packetFactory.SystemMessagePacket("[Proxy] Incoming EQ Report from PSO2es: %s" % (msg_eq[ship]), 0x0).build() else: SMPacket = packetFactory.SystemMessagePacket("[Proxy] No new EQ Report from PSO2es", 0x0).build() client.send_crypto_packet(SMPacket)
def call_from_client(self, client): global maintmode maintmode = not maintmode if maintmode: client.send_crypto_packet(packetFactory.SystemMessagePacket("{yel}[PCP Bot] {gre}Maintenance mode: {ora}ON{gre}.", 0x3).build()) return else: client.send_crypto_packet(packetFactory.SystemMessagePacket("{yel}[PCP Bot] {gre}Maintenance mode: {ora}OFF{gre}.", 0x3).build()) return
def call_from_client(self, client): if client.playerId is not None: client_prefs = data.clients.connectedClients[client.playerId].preferences if len(self.args.split(" ", 1)) < 2: client.send_crypto_packet(packetFactory.SystemMessagePacket("[Command] {red}Invalid usage. Usage: gprefix <Prefix or PSO2 Color Code>", 0x3).build()) return prefix = self.args.split(" ", 1)[1] client_prefs['globalChatPrefix'] = prefix client.send_crypto_packet(packetFactory.SystemMessagePacket("[Command] {gre}Your prefix has been set.", 0x3).build())
def call_from_client(self, client): global maintmode maintmode = not maintmode if maintmode: client.send_crypto_packet(packetFactory.SystemMessagePacket("[Maint] Maintenance mode turned on.", 0x3).build()) return else: client.send_crypto_packet(packetFactory.SystemMessagePacket("[Maint] Maintenance mode turned off.", 0x3).build()) return
def call_from_client(self, client): message = None print(self.args) if len(self.args.split(' ', 1)) < 2: client.send_crypto_packet(packetFactory.SystemMessagePacket("[Command] {red}Invalid usage.\n(Usage: %sglobalmsg <message>)" % config.globalConfig.get_key('commandPrefix'), 0x3).build()) return message = self.args.split(' ', 1)[1] for client in data.clients.connectedClients.values(): if client.get_handle() is not None: client.get_handle().send_crypto_packet( packetFactory.SystemMessagePacket("[Proxy Global Message] %s" % message, 0x0).build())
def call_from_client(self, client): client_preferences = clients.connectedClients[ client.playerId].preferences ship = (client_preferences.get_preference('eqalert_ship') - 1) if not data_eq[ship] == "": SMPacket = packetFactory.SystemMessagePacket( "[EQ Alert] Incoming EQ Report: %s" % (data_eq[ship]), 0x0).build() else: SMPacket = packetFactory.SystemMessagePacket( "[EQ Alert] There is no incoming EQ.", 0x0).build() client.send_crypto_packet(SMPacket)
def call_from_client(self, client): """ :param client: ShipProxy.ShipProxy """ if len(self.args.split(" ", 1)) < 2: client.send_crypto_packet( packetFactory.SystemMessagePacket( "[Command] {red}Invalid usage. gmute <Player Name>" ).build() ) return user_to_mute = self.args.split(" ", 1)[1] if user_to_mute.isdigit() and int(user_to_mute) in data.clients.connectedClients: data.clients.connectedClients[int(user_to_mute)].preferences['chatMuted'] = True client.send_crypto_packet(packetFactory.SystemMessagePacket("[Command] {gre}Muted %s." % user_to_mute, 0x3).build()) return else: for player_id, player_data in data.players.playerList.items(): if player_data[0].rstrip("\0") == user_to_mute: if player_id in data.clients.connectedClients: data.clients.connectedClients[player_id].preferences['chatMuted'] = True client.send_crypto_packet( packetFactory.SystemMessagePacket( "[Command] {}Muted {}.".format( "{gre}", player_data[0].rstrip("\0") ), 0x3 ).build() ) return else: client.send_crypto_packet( packetFactory.SystemMessagePacket( "[Command] {}{} either is not connected or is not part of the proxy.".format( "{red}", player_data[0].rstrip("\0") ), 0x3 ).build() ) return client.send_crypto_packet( packetFactory.SystemMessagePacket( "[Command] {}{} either is not connected or is not part of the proxy.".format( "{red}", user_to_mute ), 0x3 ).build() )
def call_from_client(self, client): global whitelistmode whitelistmode = not whitelistmode if whitelistmode: client.send_crypto_packet( packetFactory.SystemMessagePacket( "[Whitelist] Whitelist turn on.", 0x3).build()) return else: client.send_crypto_packet( packetFactory.SystemMessagePacket( "[Whitelist] Whitelist turn off.", 0x3).build()) return
def call_from_client(self, client): global geoipenabled geoipenabled = not geoipenabled if geoipenabled: client.send_crypto_packet( packetFactory.SystemMessagePacket("[GeoIP] Whitelist turn on.", 0x3).build()) return else: client.send_crypto_packet( packetFactory.SystemMessagePacket( "[GeoIP] Whitelist turn off.", 0x3).build()) return
def call_from_client(self, client): string = "=== PSO2Proxy Commands ===\n" user_command_count = 0 for command, cData in sorted(commandList.iteritems()): if cData[1] is not None: if cData[2] is not None: if not cData[2]: user_command_count += 1 string += "%s%s - %s\n\n" % ( config.globalConfig['commandPrefix'], command, cData[1]) else: user_command_count += 1 string += "%s%s - %s\n\n" % ( config.globalConfig['commandPrefix'], command, cData[1]) for command, cData in sorted(plugin_manager.commands.iteritems()): if cData[1] is not None: if cData[2] is not None: if not cData[2]: user_command_count += 1 string += "%s%s - %s\n\n" % ( config.globalConfig['commandPrefix'], command, cData[1]) else: user_command_count += 1 string += "%s%s - %s\n\n" % ( config.globalConfig['commandPrefix'], command, cData[1]) string += "{}suhelp - [Admin Only] Display proxy administrator command list.\n\n".format( config.globalConfig['commandPrefix']) # i add this manually because don't know how to get specific command. string += "=== %i commands in total ===" % user_command_count client.send_crypto_packet( packetFactory.SystemMessagePacket(string, 0x2).build())
def privmsg(self, user, channel, msg): if channel == self.factory.channel: if self.ircOutput is True: print("[GlobalChat] [IRC] <%s> %s" % (user.split("!")[0], replace_irc_with_pso2(msg).decode('utf-8'))) TCPacket = packetFactory.TeamChatPacket( self.get_user_id(user.split("!")[0]), "[GIRC] %s" % user.split("!")[0], "%s%s" % (gchatSettings['prefix'], replace_irc_with_pso2(msg).decode('utf-8'))).build() SMPacket = packetFactory.SystemMessagePacket( "[GIRC] <%s> %s" % (user.split("!")[0], "%s%s" % (gchatSettings['prefix'], replace_irc_with_pso2(msg).decode('utf-8'))), 0x3).build() for client in data.clients.connectedClients.values(): if client.preferences.get_preference( 'globalChat') and client.get_handle() is not None: if lookup_gchatmode(client.preferences) == 0: client.get_handle().send_crypto_packet(TCPacket) else: client.get_handle().send_crypto_packet(SMPacket) else: print("[IRC] <%s> %s" % (user, msg))
def call_from_client(self, client): client_config = dbManager.get_data_for_sega_id(client.myUsername) client_config['logPackets'] = True client.send_crypto_packet( packetFactory.SystemMessagePacket( "[PacketLogging] {gre}You have enabled packet logging! Thank you! Track your data at http://pso2proxy.cyberkitsune.net/redpill/", 0x3).build())
def call_from_client(self, client): preferences = data.clients.connectedClients[ client.playerId].preferences preferences.set_preference("globalChat", False) client.send_crypto_packet( packetFactory.SystemMessagePacket( "[GlobalChat] Global chat disabled for you.", 0x3).build())
class ListClients(Command): def call_from_client(self, pclient): string = "=== Players yang online: %i === \n" % len(data.clients.connectedClients) for ip, client in data.clients.connectedClients.iteritems(): client_handle = client.get_handle() if client_handle is None: continue client_host = client_handle.transport.getPeer().host client_segaid = client_handle.myUsername if client_segaid is None: continue client_segaid = client_segaid.rstrip('\0') client_player_id = client_handle.playerId if client_player_id in data.players.playerList: client_player_name = data.players.playerList[client_player_id][0].rstrip('\0') else: client_player_name = None client_ship = None client_block = None block_number = client_handle.transport.getHost().port if block_number in data.blocks.blockList: client_ship = data.clients.get_ship_from_port(block_number) client_block = data.blocks.blockList[block_number][1].rstrip('\0') string += "[Ship-%s : %s | %s] \n" % ( client_ship, client_block[:5], client_player_name) pclient.send_crypto_packet(packetFactory.SystemMessagePacket(string, 0x2).build())
def action(self, user, channel, msg): if not check_irc_with_pso2(msg): return if channel == self.factory.channel: if self.ircOutput is True: print("[GlobalChat] [Discord] * %s %s" % (user, replace_irc_with_pso2(msg).decode( 'utf-8', 'ignore'))) for client in data.clients.connectedClients.values(): if client.preferences.get_preference( 'globalChat') and client.get_handle() is not None: if lookup_gchatmode(client.preferences) == 0: client.get_handle().send_crypto_packet( packetFactory.TeamChatPacket( self.get_user_id(user.split("!")[0]), "[Discord] %s" % user.split("!")[0], "[Discord] %s" % user.split("!")[0], "* %s%s" % (client.preferences.get_preference( 'globalChatPrefix'), replace_irc_with_pso2(msg).decode( 'utf-8', 'ignore'))).build()) else: client.get_handle().send_crypto_packet( packetFactory.SystemMessagePacket( "[Discord] <%s> * %s" % (user.split("!")[0], "%s%s" % (client.preferences.get_preference( 'globalChatPrefix'), replace_irc_with_pso2(msg).decode( 'utf-8', 'ignore'))), 0x3).build())
def notify_and_config(client): """ :type client: ShipProxy.ShipProxy """ client_config = dbManager.get_data_for_sega_id(client.myUsername) if 'logPackets' not in client_config: client_config['logPackets'] = False if client_config['logPackets']: client.send_crypto_packet( packetFactory.SystemMessagePacket( "[PacketLogging] {gre}You have opted-in to packet logging, Thank you! View your contributions on http://pso2proxy.cyberkitsune.net/redpill/ or use !optout to opt out", 0x3).build()) else: client.send_crypto_packet( packetFactory.SystemMessagePacket( "[PacketLogging] {red}You have not opted-in to packet logging, and it has been disabled. Use !optin to opt in.", 0x3).build())
def call_from_client(self, client): if len(self.args.split(" ")) < 2: client.send_crypto_packet( packetFactory.SystemMessagePacket("[Proxy] {red}Invalid usage.\n(Usage: %sdeop <SegaID>)" % config.globalConfig.get_key('commandPrefix'), 0x3).build()) return player = self.args.split(" ")[1] if config.is_admin(player): current_admins = config.globalConfig.get_key('admins') current_admins.remove(player) config.globalConfig.set_key('admins', current_admins) client.send_crypto_packet( packetFactory.SystemMessagePacket("[Proxy] {gre}%s is no longer an admin." % player, 0x3).build()) else: client.send_crypto_packet( packetFactory.SystemMessagePacket("[Proxy] {red}%s is not an admin." % player, 0x3).build())
def call_from_client(self, client): archive_packets(client) client_config = dbManager.get_data_for_sega_id(client.myUsername) client_config['logPackets'] = True client.send_crypto_packet( packetFactory.SystemMessagePacket( "[PacketLogging] {red}You have disabled packet logging! :( If you change your mind, please use !optin to rejoin!", 0x3).build())