def __init__(self,serviceName,childManager = ChildsManager()): """初始化根节点 """ pb.Root() self.service = services.Service(serviceName) self.childsmanager = childManager
def OnRequestLostPassword(): global PUBLICNAME, EMAILADDRESS pname = TGEObject("LOSTPASSWORD_PUBLICNAME").getValue() email = TGEObject("LOSTPASSWORD_EMAIL").getValue() if not pname: TGECall("MessageBoxOK", "Lost Password", "Invalid Public Name") return if "@" not in email or "." not in email: TGECall("MessageBoxOK", "Lost Password", "Invalid email address") return PUBLICNAME, EMAILADDRESS = pname, email masterIP = TGEGetGlobal("$Py::MasterIP") masterPort = int(TGEGetGlobal("$Py::MasterPort")) TGECall("MessagePopup", "Contacting Master Server...", "Please wait...") factory = pb.PBClientFactory() reactor.connectTCP(masterIP, masterPort, factory) from md5 import md5 password = md5("Registration").digest() factory.login(UsernamePassword("Registration-Registration", password), pb.Root()).addCallbacks(Connected, Failure)
def ConnectToMailServer(self): print "Connecting to Mail Server Proxy at: %s"%MAILSERVER_IP factory = pb.PBClientFactory() reactor.connectTCP(MAILSERVER_IP,MAILSERVER_PORT,factory) password = md5("MSP").digest() factory.login(UsernamePassword("MSP-MSP", password),pb.Root()).addCallbacks(self.MSConnected, self.MSFailure)
def ConnectToAH(): print "Connecting to Auction House Server at: %s" % AHSERVER_IP factory = pb.PBClientFactory() reactor.connectTCP(AHSERVER_IP, AHSERVER_PORT, factory) password = md5("AH").digest() factory.login(UsernamePassword("AH-AH", password), pb.Root()).addCallbacks(AHConnected, AHFailure)
def OnRegister(): global RegPerspective regkey = TGEObject("REGISTERDLG_REGKEY").getValue() publicName = TGEObject("REGISTERDLG_PUBLICNAME").getValue() email = TGEObject("REGISTERDLG_EMAILADDRESS").getValue() verify = TGEObject("REGISTERDLG_VERIFYEMAILADDRESS").getValue() #if you just paste into a textctrl it's variable isn't being updated, unless you type into it... grrrr #print type(regkey),type(email),type(verify) try: #if not len(regkey) or not len(email) or not len(verify) or not len(publicName): if not len(email) or not len(verify) or not len(publicName): return except: return if len(publicName) < 4: TGECall("MessageBoxOK", "Invalid Entry", "Your public name must be at least 4 characters.") return if not publicName.isalpha(): TGECall( "MessageBoxOK", "Invalid Entry", "Your public name must not have numbers or other punctuation.") return if email != verify: TGECall("MessageBoxOK", "Error!", "Emails don't match. Please carefully enter your email...") return if "@" not in email: TGECall( "MessageBoxOK", "Error!", "Invalid email address. Please carefully enter your email...") return #todo, validate email form masterIP = TGEGetGlobal("$Py::MasterIP") masterPort = int(TGEGetGlobal("$Py::MasterPort")) TGECall("MessagePopup", "Communicating with Master Server...", "Please wait...") factory = pb.PBClientFactory() reactor.connectTCP(masterIP, masterPort, factory) from md5 import md5 password = md5("Registration").digest() factory.login(UsernamePassword("Registration-Registration", password), pb.Root()).addCallbacks(Connected, Failure)
def OnMasterSelectWorld(): global WORLDINFO pname = TGEGetGlobal("$pref::PublicName") if pname == "ThePlayer": #this causes problems, conflict with Single Player ? TGESetGlobal("$pref::PublicName", "") tc = TGEObject("MasterWorldList") sr = int(tc.getSelectedId()) winfo = FILTERED_WORLDS[sr] WORLDINFO = winfo if "Free " not in WORLDINFO.worldName and RPG_BUILD_DEMO: TGECall( "MessageBoxOK", "Premium Edition Required", "This server requires the Premium Edition.\n\nPlease see http://www.prairiegames.com for more information." ) return #if "Free " in WORLDINFO.worldName: TGEObject("SPONSORBREAK_BAR").visible = False if "Free " in WORLDINFO.worldName or "Premium " in WORLDINFO.worldName: TGESetGlobal("$Py::WORLDNAME", "PrairieWorld") else: TGESetGlobal("$Py::WORLDNAME", winfo.worldName) #if the world has a player password, snag it here password = "" #connect to world and see if we have an account TGECall("MessagePopup", "Contacting World...", "Please wait...") try: wn = WORLDINFO.worldName.replace(" ", "_") x = TGEGetGlobal("$pref::WorldPassword_%s" % wn) if len(x) == 8: TGESetGlobal("$pref::WorldPassword", x) except: pass if "Premium " in winfo.worldName or "Free " in winfo.worldName: #official server MasterPerspective.callRemote("PlayerAvatar", "submitPlayerToWorld", winfo.worldName).addCallbacks( PlayerSubmittedToWorld, Failure) else: factory = pb.PBClientFactory() reactor.connectTCP(winfo.worldIP, winfo.worldPort, factory) from md5 import md5 password = md5(password).digest() factory.login(UsernamePassword("NewPlayer-NewPlayer", password), pb.Root()).addCallbacks(NewPlayerConnected, Failure)
def QueryWorldInfo(worldname): for winfo in WORLDS: if winfo.worldName == worldname: factory = pb.PBClientFactory() reactor.connectTCP(winfo.worldIP, winfo.worldPort, factory) from md5 import md5 password = md5("").digest() factory.login(UsernamePassword("Query-Query", password), pb.Root()).addCallbacks(QueryWorldInfoConnected, QueryWorldInfoFailure, (winfo.worldName, ), {}, (winfo.worldName, )) return True return False
def GetWorldStats(): username = "******" password = STATSERVERPASSWORD factory = pb.PBClientFactory() reactor.connectTCP(WORLDIP, WORLDPORT, factory) #the pb.Root() is a bit of a hack, I don't know how to get host address on server without #sending it, and I don't want to take the time to figure it out at the moment from md5 import md5 password = md5(password).digest() factory.login(UsernamePassword(username, password), pb.Root()).addCallbacks(GetWorldStatsConnected, GetWorldStatsFailure)
def AnnounceWorld(): global ANNOUNCECALLBACK ANNOUNCECALLBACK = reactor.callLater(60, AnnounceWorld) username = "******" % PUBLICNAME password = PASSWORD password = md5(password).digest() print "Announcing World" factory = pb.PBClientFactory() reactor.connectTCP(MASTERIP, MASTERPORT, factory) #the pb.Root() is a bit of a hack, I don't know how to get host address on server without #sending it, and I don't want to take the time to figure it out at the moment factory.login(UsernamePassword(username, password), pb.Root()).addCallbacks(AnnounceConnected, AnnounceFailure)
def PyOnDirectSelectWorld(): global WORLDINFO TGEEval("Canvas.popDialog(DirectConnectWnd);") pname = TGEGetGlobal("$pref::PublicName") if pname == "ThePlayer": #this causes problems, conflict with Single Player ? TGESetGlobal("$pref::PublicName", "") ip = TGEObject("DIRECTIP_IP").getValue() #FIX ME!!! if "72.36." in ip: return if "72.232." in ip: return TGECall("MessagePopup", "Contacting World...", "Please wait...") port = TGEObject("DIRECTIP_PORT").getValue() #if you just paste into a textctrl it's variable isn't being updated, unless you type into it... grrrr TGESetGlobal("$pref::DirectConnectIP", ip) TGESetGlobal("$pref::DirectConnectPort", port) try: port = int(port) except: port = 2006 from mud.client.playermind import SimMind SimMind.directConnect = ip WORLDINFO = WorldInfo() WORLDINFO.worldName = "DirectConnection" WORLDINFO.worldIP = ip WORLDINFO.worldPort = port WORLDINFO.hasPlayerPassword = True TGESetGlobal("$Py::WORLDNAME", "DirectConnection") password = "" from md5 import md5 password = md5(password).digest() factory = pb.PBClientFactory() reactor.connectTCP(ip, port, factory) factory.login(UsernamePassword("NewPlayer-NewPlayer", password), pb.Root()).addCallbacks(NewPlayerConnected, Failure)
def test_connectionLost(self): """ If there is an error issuing the request to the remote publisher, an error response is returned. """ # Using pb.Root as a publisher will cause request calls to fail with an # error every time. Just what we want to test. self.f1 = serverFactory = PBServerFactory(pb.Root()) self.port1 = serverPort = reactor.listenTCP(0, serverFactory) self.sub = subscription = distrib.ResourceSubscription( "127.0.0.1", serverPort.getHost().port) request = DummyRequest([b""]) d = _render(subscription, request) def cbRendered(ignored): self.assertEqual(request.responseCode, 500) # This is the error we caused the request to fail with. It should # have been logged. errors = self.flushLoggedErrors(pb.NoSuchMethod) self.assertEqual(len(errors), 1) # The error page is rendered as HTML. expected = [ b"", b"<html>", b" <head><title>500 - Server Connection Lost</title></head>", b" <body>", b" <h1>Server Connection Lost</h1>", b" <p>Connection to distributed server lost:" b"<pre>" b"[Failure instance: Traceback from remote host -- " b"twisted.spread.flavors.NoSuchMethod: " b"No such method: remote_request", b"]</pre></p>", b" </body>", b"</html>", b"", ] self.assertEqual([b"\n".join(expected)], request.written) d.addCallback(cbRendered) return d
def DoMasterLogin(): from masterGui import MasterPerspective if MasterPerspective and not MasterPerspective.broker.disconnected: from masterGui import Setup Setup(MasterPerspective) return regkey = TGEObject("MASTERLOGIN_PUBLICNAME").getValue() password = TGEObject("MASTERLOGIN_PASSWORD").getValue() #if you just paste into a textctrl it's variable isn't being updated, unless you type into it... grrrr TGESetGlobal("$pref::PublicName",regkey) TGESetGlobal("$pref::MasterPassword",password) #print type(regkey),type(email),type(verify) if not len(regkey) or not len(password): TGEEval("Canvas.setContent(MainMenuGui);") TGECall("MessageBoxOK","Error","Invalid username or password.") return TGEObject("PATCHLOGIN_PUBLICNAME").setText(regkey) TGEObject("PATCHLOGIN_PASSWORD").setText(password) TGEObject("MASTERLOGIN_PUBLICNAME").setText(regkey) TGEObject("MASTERLOGIN_PASSWORD").setText(password) #todo, validate email form masterIP = TGEGetGlobal("$Py::MasterIP") masterPort = int(TGEGetGlobal("$Py::MasterPort")) TGECall("MessagePopup","Logging into Master Server...","Please wait...") factory = pb.PBClientFactory() reactor.connectTCP(masterIP,masterPort,factory) from md5 import md5 password = md5(password).digest() factory.login(UsernamePassword("%s-Player"%regkey, password),pb.Root()).addCallbacks(Connected, Failure)
def test_connectionLost(self): """ If there is an error issuing the request to the remote publisher, an error response is returned. """ # Using pb.Root as a publisher will cause request calls to fail with an # error every time. Just what we want to test. self.f1 = serverFactory = PBServerFactory(pb.Root()) self.port1 = serverPort = reactor.listenTCP(0, serverFactory) self.sub = subscription = distrib.ResourceSubscription( "127.0.0.1", serverPort.getHost().port) request = DummyRequest(['']) d = _render(subscription, request) def cbRendered(ignored): self.assertEqual(request.responseCode, 500) # This is the error we caused the request to fail with. It should # have been logged. self.assertEqual(len(self.flushLoggedErrors(pb.NoSuchMethod)), 1) d.addCallback(cbRendered) return d
def LaunchWorld(): print "####Launching world" if not CoreSettings.PGSERVER: username=PUBLICNAME+"-"+"World" password=PASSWORD password = md5(password).digest() factory = pb.PBClientFactory() reactor.connectTCP(MASTERIP,MASTERPORT,factory) print "####Connecting to Master: " + str([MASTERIP, MASTERPORT]) factory.login(UsernamePassword(username, password),pb.Root()).addCallbacks(LaunchWorldConnected, AnnounceFailure) else: world = World.byName("TheWorld") ip = get_IP() if not ip: print_stack() print "AssertionError: Error getting WAN address!" return print "WAN IP found: ",ip #temporary, need to be able to set individual zone ip's world.zoneIP = ip SpawnZones()
def __init__(self, dnsmanager=ChildsManager()): '''初始化根节点 ''' pb.Root() self.service = None self.childsmanager = dnsmanager