Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

GlobalMgr Packet Proxy [Python]

RaGEZONE VIP
[VIP] Member
Joined
Oct 10, 2019
Messages
198
Reaction score
454
Alternative http://forum.ragezone.com/f459/globalmgr-packet-proxy-932596/

Benefits:
  • Written in Python 3 - no need to use Mono, less resource consumption.
  • Supports work with several clients - you can attach several channels to one port.
  • There is no need to change the source code - everything you need is specified as command line arguments.
  • Multiple instances can be run with different arguments.

Download link:

/home/proxy/proxy.py
Code:
#!/usr/bin/python3.6

import socket

import select

import time

import sys



# Changing the buffer_size and delay, you can improve the speed and bandwidth.

# But when buffer get to high or delay go too down, you can broke things

buffer_size = 2048

delay = 0.0001

port_in = int(sys.argv[1])
port_out = int(sys.argv[2])
filename_item = bytes("Data/"+sys.argv[3]+".scp", "utf8")
filename_mobs = bytes("Data/"+sys.argv[4]+".scp", "utf8")

filename_item = filename_item+bytes(64-len(filename_item))
filename_mobs = filename_mobs+bytes(64-len(filename_mobs))

forward_to = ('', port_out)



class Forward:

    def __init__(self):

        self.forward = socket.socket(socket.AF_INET, socket.SOCK_STREAM)



    def start(self, host, port):

        try:

            self.forward.connect((host, port))

            return self.forward

        except Exception as e:

            print(e)

            return False



class TheServer:

    input_list = []

    channel = {}



    def __init__(self, host, port):

        self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        self.server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

        self.server.bind((host, port))

        self.server.listen(200)



    def main_loop(self):

        self.input_list.append(self.server)

        while 1:

            time.sleep(delay)

            ss = select.select

            inputready, outputready, exceptready = ss(self.input_list, [], [])

            for self.s in inputready:

                if self.s == self.server:

                    self.on_accept()

                    break



                self.data = self.s.recv(buffer_size)

                if len(self.data) == 0:

                    self.on_close()

                    break

                else:

                    self.on_recv()



    def on_accept(self):

        forward = Forward().start(forward_to[0], forward_to[1])

        clientsock, clientaddr = self.server.accept()

        if forward:

            print (clientaddr, "has connected")

            self.input_list.append(clientsock)

            self.input_list.append(forward)

            self.channel[clientsock] = forward

            self.channel[forward] = clientsock

        else:

            print ("Can't establish connection with remote server."),

            print ("Closing connection with client side", clientaddr)

            clientsock.close()



    def on_close(self):

        print (self.s.getpeername(), "has disconnected")

        #remove objects from input_list

        self.input_list.remove(self.s)

        self.input_list.remove(self.channel[self.s])

        out = self.channel[self.s]

        # close the connection with client

        self.channel[out].close()  # equivalent to do self.s.close()

        # close the connection with remote server

        self.channel[self.s].close()

        # delete both objects from channel dict

        del self.channel[out]

        del self.channel[self.s]



    def on_recv(self):

        data = self.data

        # here we can parse and/or modify the data before send forward
        
        if len(data) == 785:
            opCode = data[8:10]
            if opCode == b'\xf7\x02':
                data = data[:15]+filename_item+data[79:272]+filename_mobs+data[336:]
                # print (data)

        

        self.channel[self.s].send(data)



if __name__ == '__main__':

        server = TheServer('', port_in)

        try:

            server.main_loop()

        except KeyboardInterrupt:

            print ("Ctrl C - Stopping server")

            sys.exit(1)

Usage example:

Preparation:
Code:
yum install python36 screen

/home/proxy/proxy.sh
Code:
#!/bin/bash
python3.6 /home/proxy/proxy.py [B]Port_IN[/B] [B]Port_OUT[/B] [B]Item_NEW[/B] [B]Mobs_NEW[/B]
# Port_IN - the GlobalMgr port specified by you in WorldSvr_XX_XX.ini (ex. 12345)
# Port_OUT - the real port of GlobalMgr as specified by you in GlobalMgrSvr.ini (ex. 38170)
# Item_NEW - The file name that will be used (without the extension)
# Mobs_NEW - The file name that will be used (without the extension)

/etc/systemd/system/gms-proxy.service

Code:
[Unit]
Description=Cabal Global manager Proxy
After=network.target

[Service]
Type=forking
Restart=always
RestartSec=3
StartLimitIntervalSec=500
StartLimitBurst=5
User=root
ExecStart=/bin/bash -c 'screen -d -m -S [B]Some_unique_name[/B] /home/proxy/proxy.sh'
# Some_unique_name - Unique Screen session name (ex. My_Special_Channel_1)

[Install]
WantedBy=multi-user.target
Set permissions and service registration:
Code:
chmod 0700 /home/proxy/proxy.sh
systemctl daemon-reexec

Start the service and add it to autostart:
Code:
systemctl start gms-proxy
systemctl status gms-proxy
systemctl enable gms-proxy
 
Back
Top