def __init__(self,World,render,base):
        self.World = World;
        self.authConnection = AuthConnectionModel(self)
        self.nullConnection = NullConnectionModel()
        self.taskName = "nullTask"
        self.World.ServerConnection.setupConnectionModel(self.authConnection)
        self.World.ServerConnection.setupConnectionModel(self.nullConnection)
        
        boxloc = Vec3(0.0, 0.0, 0.0)
        p = boxloc
        self.LoginFrame = DirectFrame(frameColor=(0,0,0,0.4),frameSize=(-0.5,0.41,-0.25,0.1),pos=p)       

        p = boxloc + Vec3(-0.5, 0, 0.0)                                 
        self.LoginFrame.textObject = OnscreenText(parent=self.LoginFrame, text = "Username:"******"" , pos = p, scale=.05, initialText="", numLines = 1)
        
        p = boxloc + Vec3(-0.5, -0.1, 0.0)        
        self.LoginFrame.textObject = OnscreenText(parent=self.LoginFrame, text = "Password:"******"" , pos = p, scale=.05, initialText="", numLines = 1, obscured = 1)
        
        p = boxloc + Vec3(-0.2, 0, -0.2)
        self.LoginFrame.loginButton = DirectButton(parent=self.LoginFrame, text = ("Login", "Login", "Login", "Login"), pos = p, scale = 0.075, command=self.attemptLogin)
        
        p = boxloc + Vec3(0.2, 0, -0.2)
        self.LoginFrame.registerButton = DirectButton(parent=self.LoginFrame, text = ("Signup", "Signup", "Signup", "Signup"), pos = p, scale = 0.075, command=self.attemptRegister)
        
        p = boxloc + Vec3(0, -0.4, 0)
        self.LoginFrame.statusText = OnscreenText(parent=self.LoginFrame, text = "", pos = p, scale = 0.075, fg = (1, 0, 0, 1), align=TextNode.ACenter)
        
        self.World.taskMgr.doMethodLater(5,self.sendNullSignal,self.taskName)
Ejemplo n.º 2
0
    def __init__(self):
        print("began")
        self.taskMgr = taskMgr
        with open('config.json') as data_file:    
            self.conf = json.load(data_file)
        self.ServerConnection = ServerConnection()#uncomment when going live
        self.ServerConnection.connect(self.conf['host'],self.conf['port'])#uncomment when going live
        props = WindowProperties( )
        props.setTitle( 'Log In' )
        props.setFixedSize(True)
        props.setSize(1280,740)
        props.setOrigin(-2,-2)
        base.win.requestProperties( props )
        self.base = ShowBase
        self.main_theme = base.loader.loadSfx("assets/sounds/terminator_theme.ogg")
        self.main_theme.play()
        
        self.username = ""
        self.balance = "900000"

        self.authConnection = AuthConnectionModel(self)#uncomment when going live
        self.authConnection.setHandler(self.parseAuthResponse, self.parseRegResponse)
        self.ServerConnection.setupConnectionModel(self.authConnection)#uncomment when going live
       
        
        self.heartbeatConnection = HeartbeatConnectionModel()#uncomment when going live
        
        self.ServerConnection.setupConnectionModel(self.heartbeatConnection)#uncomment when going live
        
        
        self.taskMgr.doMethodLater(self.conf['heartbeatRate'], self.doHeartbeat, "heartbeat")#uncomment when going live
        
        self.taskMgr.doMethodLater(self.conf['heartbeatRate'], self.doHeartbeat, "heartbeat")
        
        self.screen = Login(self)#uncomment when going live
        #self.screen = Menu(self)#comment this one when you are trying to log into it like normal

        
        self.taskMgr.doMethodLater(self.conf['heartbeatRate'], self.doHeartbeat, "heartbeat")
        
        self.taskMgr.doMethodLater(1, self.doSong, "song")
        
        self.screenType = "login"
        self.screen.run()
class AuthScreen:
    def __init__(self,World,render,base):
        self.World = World;
        self.authConnection = AuthConnectionModel(self)
        self.nullConnection = NullConnectionModel()
        self.taskName = "nullTask"
        self.World.ServerConnection.setupConnectionModel(self.authConnection)
        self.World.ServerConnection.setupConnectionModel(self.nullConnection)
        
        boxloc = Vec3(0.0, 0.0, 0.0)
        p = boxloc
        self.LoginFrame = DirectFrame(frameColor=(0,0,0,0.4),frameSize=(-0.5,0.41,-0.25,0.1),pos=p)       

        p = boxloc + Vec3(-0.5, 0, 0.0)                                 
        self.LoginFrame.textObject = OnscreenText(parent=self.LoginFrame, text = "Username:"******"" , pos = p, scale=.05, initialText="", numLines = 1)
        
        p = boxloc + Vec3(-0.5, -0.1, 0.0)        
        self.LoginFrame.textObject = OnscreenText(parent=self.LoginFrame, text = "Password:"******"" , pos = p, scale=.05, initialText="", numLines = 1, obscured = 1)
        
        p = boxloc + Vec3(-0.2, 0, -0.2)
        self.LoginFrame.loginButton = DirectButton(parent=self.LoginFrame, text = ("Login", "Login", "Login", "Login"), pos = p, scale = 0.075, command=self.attemptLogin)
        
        p = boxloc + Vec3(0.2, 0, -0.2)
        self.LoginFrame.registerButton = DirectButton(parent=self.LoginFrame, text = ("Signup", "Signup", "Signup", "Signup"), pos = p, scale = 0.075, command=self.attemptRegister)
        
        p = boxloc + Vec3(0, -0.4, 0)
        self.LoginFrame.statusText = OnscreenText(parent=self.LoginFrame, text = "", pos = p, scale = 0.075, fg = (1, 0, 0, 1), align=TextNode.ACenter)
        
        self.World.taskMgr.doMethodLater(5,self.sendNullSignal,self.taskName)

    def sendNullSignal(self,task):
        self.nullConnection.sendNull()
        return task.again
        
    def updateStatus(self, statustext):
        self.LoginFrame.statusText.setText(statustext)
        
    def unloadScreen(self):
        self.LoginFrame.destroy()
        self.World.taskMgr.remove(self.taskName)
        
    def attemptRegister(self):
        self.whichAction = 1      
        if(self.LoginFrame.usernameBox.get() == ""):
            if(self.LoginFrame.passwordBox.get() == ""):
                self.updateStatus("ERROR: You must enter a username and password before logging in.")
            else:
                self.updateStatus("ERROR: You must specify a username")
            self.LoginFrame.passwordBox['focus'] = 0
            self.LoginFrame.usernameBox['focus'] = 1
                
        elif(self.LoginFrame.passwordBox.get() == ""):
            self.updateStatus("ERROR: You must enter a password")
            self.LoginFrame.usernameBox['focus'] = 0
            self.LoginFrame.passwordBox['focus'] = 1
            
        else:
            self.updateStatus("Attempting to Signup...")
            self.LoginFrame.registerButton = DGG.DISABLED
            self.LoginFrame.loginButton = DGG.DISABLED
            if not self.World.bypassServer:
                self.authConnection.sendRegisterRequest(self.LoginFrame.usernameBox.get(),self.LoginFrame.passwordBox.get())
            else:
                self.parseResponse(1)
            
        
    def attemptLogin(self):  
        self.whichAction = 2    
        if(self.LoginFrame.usernameBox.get() == ""):
            if(self.LoginFrame.passwordBox.get() == ""):
                self.updateStatus("ERROR: You must enter a username and password before logging in.")
            else:
                self.updateStatus("ERROR: You must specify a username")
            self.LoginFrame.passwordBox['focus'] = 0
            self.LoginFrame.usernameBox['focus'] = 1
                
        elif(self.LoginFrame.passwordBox.get() == ""):
            self.updateStatus("ERROR: You must enter a password")
            self.LoginFrame.usernameBox['focus'] = 0
            self.LoginFrame.passwordBox['focus'] = 1
            
        else:
            self.updateStatus("Attempting to login...")
            self.LoginFrame.registerButton = DGG.DISABLED
            self.LoginFrame.loginButton = DGG.DISABLED
            if self.LoginFrame.usernameBox.get() == "test" and self.LoginFrame.passwordBox.get() == "test":
                self.parseResponse(1)
            elif not self.World.bypassServer:
                self.authConnection.sendLoginRequest(self.LoginFrame.usernameBox.get(),self.LoginFrame.passwordBox.get())
            else:
                self.parseResponse(1)
            
    def parseAuthResponse(self,data):
        if data == 1:
            self.unloadScreen()
            self.World.doMainMenuScreen()
            # self.World.doSelectionScreen()
        else: 
            if data == 2:
                self.updateStatus("Already logged in")
            elif self.whichAction == 1:
                self.updateStatus("Unable to register with that username")
            else:
                self.updateStatus("Invalid username/password")
            self.whichAction = 0
Ejemplo n.º 4
0
class World(DirectObject):
    #client side making it easier and not having to log in everytime for debuging just follow the comments
    def __init__(self):
        print("began")
        self.taskMgr = taskMgr
        with open('config.json') as data_file:    
            self.conf = json.load(data_file)
        self.ServerConnection = ServerConnection()#uncomment when going live
        self.ServerConnection.connect(self.conf['host'],self.conf['port'])#uncomment when going live
        props = WindowProperties( )
        props.setTitle( 'Log In' )
        props.setFixedSize(True)
        props.setSize(1280,740)
        props.setOrigin(-2,-2)
        base.win.requestProperties( props )
        self.base = ShowBase
        self.main_theme = base.loader.loadSfx("assets/sounds/terminator_theme.ogg")
        self.main_theme.play()
        
        self.username = ""
        self.balance = "900000"

        self.authConnection = AuthConnectionModel(self)#uncomment when going live
        self.authConnection.setHandler(self.parseAuthResponse, self.parseRegResponse)
        self.ServerConnection.setupConnectionModel(self.authConnection)#uncomment when going live
       
        
        self.heartbeatConnection = HeartbeatConnectionModel()#uncomment when going live
        
        self.ServerConnection.setupConnectionModel(self.heartbeatConnection)#uncomment when going live
        
        
        self.taskMgr.doMethodLater(self.conf['heartbeatRate'], self.doHeartbeat, "heartbeat")#uncomment when going live
        
        self.taskMgr.doMethodLater(self.conf['heartbeatRate'], self.doHeartbeat, "heartbeat")
        
        self.screen = Login(self)#uncomment when going live
        #self.screen = Menu(self)#comment this one when you are trying to log into it like normal

        
        self.taskMgr.doMethodLater(self.conf['heartbeatRate'], self.doHeartbeat, "heartbeat")
        
        self.taskMgr.doMethodLater(1, self.doSong, "song")
        
        self.screenType = "login"
        self.screen.run()
    
    def doHeartbeat(self,task):
        self.heartbeatConnection.sendHeartbeat()
        return task.again
    
    def doSong(self,task):
        if self.main_theme.status() == self.main_theme.READY:
            self.main_theme.play()
        return task.again
    
    def doMenu(self):
        print("doing menu")
        self.screen.unloadScreen()
        self.screenType = "menu"
        self.screen = Menu(self)
    
    def parseAuthResponse(self,data):
        if data == 1:
            print("unloading")
            self.doMenu()
        else: 
            if data == 2:
                self.screen.setStatusText("Already logged in")
            else:
                self.screen.setStatusText("Invalid username/password")   
            self.screen.enter_btn['state'] = DGG.NORMAL
            self.screen.register_btn['state'] = DGG.NORMAL        
        
    def parseRegResponse(self,data):
        if data == 1:
            print("unloading")
            self.doMenu()
        else:
            self.screen.setStatusText("User already exists")   
            self.screen.cancel_btn['state'] = DGG.NORMAL
            self.screen.register_btn['state'] = DGG.NORMAL