Example Plugins

Plugins must be saved inside the Plugins folder otherwise they will not be loaded.

Packet Processing Plugin

This simple plugin will display all packets going to/from Silkroad/Joymax.

from phBot import *

# Called when the bot successfully connects to the game server
def connected():
    pass

# All packets received from Silkroad will be passed to this function
# Returning True will keep the packet and False will not forward it to the game server
def handle_silkroad(opcode, data):
    log('Python: (Silkroad) 0x%02X' % opcode)
    return True

# All packets received from Joymax will be passed to this function
# Returning True will keep the packet and False will not forward it to the client
def handle_joymax(opcode, data):
    log('Python: (Joymax) 0x%02X' % opcode)
    return True

# Called when the character enters the game world
def joined_game():
    pass

# Called when the character teleports
# This function will also be called after the "joined_game" function
def teleported():
    pass

log('[%s] Loaded' % __name__)

GUI Plugin

This next plugin creates a basic GUI on the Plugins tab inside the bot.

from phBot import *
import QtBind

gui = QtBind.init(__name__, 'GUI Example')

QtBind.createLabel(gui, 'Welcome to the GUI example Python script! From here you\'ll be able to add your own GUI to the \'Plugins\' tab inside phBot. Being able to create a UI\nopens up far more possibilies.\n\n- Do not replace the __name__ var in the QtBind.init() call. It is used for passing events to the correct module.\n- Only call QtBind.init() during module load\n- Labels are auto resized after text is set', 10, 10)

button1 = QtBind.createButton(gui, 'button_clicked', 'Button', 10, 125)
checkbox1 = QtBind.createCheckBox(gui, 'checkbox_clicked', 'Check Box', 10, 150)
label1 = QtBind.createLabel(gui, 'Label', 10, 175)
lineedit1 = QtBind.createLineEdit(gui, 'Text in box', 10, 200, 32, 16)

QtBind.createLabel(gui, 'The only downside is that you must create the UI by hand.', 10, 250)

def button_clicked():
    log('Button clicked')

def checkbox_clicked(checked):
    log('Check Box: %s' % checked)

log('[%s] Loaded' % __name__)

Socket Plugin

Sockets are now supported as of v2.0.0. Some "pyd" files were missing (aka DLLs) which caused it to not work previously.

from phBot import *
import socket

log('[%s] Loaded' % __name__)

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('www.example.com', 80))
s.send('GET / HTTP/1.0\r\nHost: www.example.com\r\n\r\n'.encode('utf-8'))
data = s.recv(1024)
s.close()

log('%s' % data)
[01:21:03] [socket_test] Loaded
[01:21:03] b'HTTP/1.0 200 OK\r\nCache-Control: max-age=604800\r\nContent-Type: text/html\r\nDate: Sun, 01 Apr 2018 05:21:01 GMT\r\nEtag: "1541025663+gzip+ident"\r\nExpires: Sun, 08 Apr 2018 05:21:01 GMT\r\nLast-Modified: Fri, 09 Aug 2013 23:54:35 GMT\r\nServer: ECS (phl/9D2C)\r\nVary: Accept-Encoding\r\nX-Cache: HIT\r\nContent-Length: 1270\r\nConnection: close\r\n\r\n<!doctype html>\n<html>\n<head>\n    <title>Example Domain</title>\n\n    <meta charset="utf-8" />\n    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />\n    <meta name="viewport" content="width=device-width, initial-scale=1" />\n    <style type="text/css">\n    body {\n        background-color: #f0f0f2;\n        margin: 0;\n        padding: 0;\n        font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;\n        \n    }\n    div {\n        width: 600px;\n        margin: 5em auto;\n        padding: 50px;\n        background-color: #fff;\n        border-radius: 1em;\n    }\n    a:link, a:visited {\n        color: #38488f;\n        text-decoration: none;\n    }\n    @med'

Last updated