Created
July 24, 2020 20:47
-
-
Save Mrestof/a4a8701d0648e637a086e38d959fb3f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wx | |
from twisted.internet import wxreactor | |
wxreactor.install() | |
from twisted.internet import reactor | |
from twisted.internet.address import IPv4Address | |
from quarry.net.client import ClientFactory, SpawningClientProtocol | |
from quarry.net.auth import OfflineProfile | |
class MyClientProtocol(SpawningClientProtocol): | |
def send_chat(self, text): | |
self.send_packet("chat_message", self.buff_type.pack_string(text)) | |
class MyClientFactory(ClientFactory): | |
protocol = MyClientProtocol | |
mc_protocol: MyClientProtocol | |
def connect(self, host, port=25565): | |
super().connect(host, port) | |
addr = IPv4Address('TCP', host, port) | |
self.mc_protocol = super().buildProtocol(addr) | |
def buildProtocol(self, addr): | |
return self.mc_protocol | |
class MyFrame(wx.Frame): | |
def __init__(self, title, mc_protocols: list, parent=None): | |
super().__init__(parent, title=title) | |
self.mc_protocols = mc_protocols | |
panel = wx.Panel(self) | |
main_sizer = wx.BoxSizer() | |
first_bot_sizer = wx.BoxSizer(wx.VERTICAL) | |
second_bot_sizer = wx.BoxSizer(wx.VERTICAL) | |
main_sizer.Add(first_bot_sizer, proportion=1, flag=wx.EXPAND) | |
main_sizer.Add(second_bot_sizer, proportion=1, flag=wx.EXPAND) | |
self.first_text_input = wx.TextCtrl(panel) | |
self.second_text_input = wx.TextCtrl(panel) | |
self.first_button = wx.Button(panel, label='send') | |
self.second_button = wx.Button(panel, label='send') | |
first_bot_sizer.AddMany([ | |
(wx.StaticText(panel, label='First Bot'), 0, wx.LEFT | wx.UP, 10), | |
(self.first_text_input, 0, wx.ALL | wx.EXPAND, 10), | |
(wx.StaticText(panel), 1, 0, 0), | |
(self.first_button, 0, wx.ALL, 10) | |
]) | |
second_bot_sizer.AddMany([ | |
(wx.StaticText(panel, label='Second Bot'), 0, wx.LEFT | wx.UP, 10), | |
(self.second_text_input, 0, wx.ALL | wx.EXPAND, 10), | |
(wx.StaticText(panel), 1, 0, 0), | |
(self.second_button, 0, wx.ALL, 10) | |
]) | |
self.Bind(wx.EVT_BUTTON, self.on_press) | |
panel.SetSizer(main_sizer) | |
self.SetSize(wx.Size(500, 150)) | |
self.Show() | |
def on_press(self, event): | |
button = event.GetEventObject() | |
if button == self.first_button: | |
value = self.first_text_input.GetValue() | |
self.mc_protocols[0].send_chat(value) | |
else: | |
value = self.second_text_input.GetValue() | |
self.mc_protocols[1].send_chat(value) | |
if __name__ == '__main__': | |
first_user = OfflineProfile('test_guy') | |
second_user = OfflineProfile('his_friend') | |
first_factory = MyClientFactory(first_user) | |
second_factory = MyClientFactory(second_user) | |
first_factory.connect('192.168.1.56', 1111) | |
second_factory.connect('192.168.1.56', 1111) | |
app = wx.App() | |
frame = MyFrame('test', [first_factory.mc_protocol, second_factory.mc_protocol]) | |
reactor.registerWxApp(app) | |
reactor.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment