Advertisement
Guest User

intrologin.py

a guest
May 14th, 2020
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 26.71 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import app
  3. import net
  4. import ui
  5. import snd
  6. import wndMgr
  7. import musicInfo
  8. import serverLoginData
  9. import systemSetting
  10. import ServerStateChecker
  11. import localeInfo
  12. import constInfo
  13. import uiCommon
  14. import ime
  15. import uiScriptLocale
  16. import time
  17. import dbg
  18. import os
  19. from _weakref import proxy
  20.  
  21. def IsLoginDelay():
  22.     return True
  23.  
  24. def GetLoginDelay():
  25.     return 4.0
  26.  
  27. #update 30.08.2019
  28. REGBUTTON   = "https://www.ephelion2.global/register"
  29. FORGOTPASS  = "https://www.ephelion2.global/lost-pw"
  30. ADMINS      = "https://www.ephelion2.global/team"
  31. DISCORD     = "https://discord.gg/EN9xYE"
  32. FACEBOOK    = "https://www.facebook.com"
  33. TWITTER     = "https://twitter.com/"
  34. INSTAGRAM   = "https://www.instagram.com/"
  35. YOUTUBE     = "https://www.youtube.com/"
  36. MESSENGER   = "https://www.facebook.com/"
  37. WHATSAPP    = "https://www.ephelion2.global/"
  38. #end
  39.  
  40. app.SetGuildMarkPath("test")
  41.  
  42. class ConnectingDialog(ui.ScriptWindow):
  43.     def __init__(self):
  44.         ui.ScriptWindow.__init__(self)
  45.         self.SetWindowName("ConnectingDialog")
  46.         self.__LoadDialog()
  47.         self.eventTimeOver = lambda *arg: None
  48.         self.eventExit = lambda *arg: None
  49.  
  50.     def __del__(self):
  51.         ui.ScriptWindow.__del__(self)
  52.  
  53.     def __LoadDialog(self):
  54.         try:
  55.             PythonScriptLoader = ui.PythonScriptLoader()
  56.             PythonScriptLoader.LoadScriptFile(self, "UIScript/ConnectingDialog.py")
  57.  
  58.             self.board = self.GetChild("board")
  59.             self.message = self.GetChild("message")
  60.             self.countdownMessage = self.GetChild("countdown_message")
  61.  
  62.         except:
  63.             import exception
  64.             exception.Abort("ConnectingDialog.LoadDialog.BindObject")
  65.  
  66.     def Open(self, waitTime):
  67.         curTime = time.clock()
  68.         self.endTime = curTime + waitTime
  69.  
  70.         self.Lock()
  71.         self.SetCenterPosition()
  72.         self.SetTop()
  73.         self.Show()    
  74.  
  75.     def Close(self):
  76.         self.Unlock()
  77.         self.ClearDictionary()
  78.         self.Hide()
  79.  
  80.     def Destroy(self):
  81.         self.Hide()
  82.         self.ClearDictionary()
  83.  
  84.     def SetText(self, text):
  85.         self.message.SetText(text)
  86.  
  87.     def SetCountDownMessage(self, waitTime):
  88.         self.countdownMessage.SetText("%.0f%s" % (waitTime, localeInfo.SECOND))
  89.  
  90.     def SAFE_SetTimeOverEvent(self, event):
  91.         self.eventTimeOver = ui.__mem_func__(event)
  92.  
  93.     def SAFE_SetExitEvent(self, event):
  94.         self.eventExit = ui.__mem_func__(event)
  95.  
  96.     def OnUpdate(self):
  97.         lastTime = max(0, self.endTime - time.clock())
  98.         if 0 == lastTime:
  99.             self.Close()
  100.             self.eventTimeOver()
  101.         else:
  102.             self.SetCountDownMessage(self.endTime - time.clock())
  103.  
  104.     def OnPressExitKey(self):
  105.         self.eventExit()
  106.         return True
  107.  
  108. class LoginWindow(ui.ScriptWindow):
  109.  
  110.     def __init__(self, stream):
  111.         print "LoginWindow::LoginWindow"
  112.         ui.ScriptWindow.__init__(self)
  113.         self.SetWindowName("LoginWindow")
  114.         net.SetPhaseWindow(net.PHASE_WINDOW_LOGIN, self)
  115.         net.SetAccountConnectorHandler(self)
  116.  
  117.         self.connectingDialog = None
  118.         self.stream = stream
  119.         self.isNowCountDown = False
  120.  
  121.         self.pickedChannel = -1
  122.  
  123.         self.loginButton = 0
  124.  
  125. #update 30.08.2019
  126.         self.ForgotPass = 0
  127.         self.TeamMembers = 0
  128.         self.Register = 0
  129.         self.Facebook = 0
  130.         self.Instagram = 0
  131.         self.Discord = 0
  132.         self.WhatsApp = 0
  133.         self.Messenger = 0
  134.         self.Twitter = 0
  135.         self.YouTube = 0
  136. #end
  137.  
  138.         self.cancelConnection = False
  139.         self.questionDialog = None
  140.         self.updateNumber = 0
  141.         self.ChannelButton = [None, None, None, None]
  142.         self.ChannelStatusImage = [None, None, None, None]
  143.         # self.Languages = [None, None, None, None, None]
  144.         self.AccountManager = [
  145.                                     [None, None, None],
  146.                                     [None, None, None],
  147.                                     [None, None, None],
  148.                                     [None, None, None],
  149.                                     [None, None, None],
  150.                                   ]
  151.         self.AccountManagerData = [
  152.                                 ["", ""],
  153.                                 ["", ""],
  154.                                 ["", ""],
  155.                                 ["", ""],
  156.                                 ["", ""],
  157.                               ]
  158.                              
  159.         # self.LanguageButtonGroup = None
  160.  
  161.     def __del__(self):
  162.         print "LoginWindow::~LoginWindow"
  163.         net.SetAccountConnectorHandler(0)
  164.         net.ClearPhaseWindow(net.PHASE_WINDOW_LOGIN, self)
  165.         ui.ScriptWindow.__del__(self)
  166.  
  167.     def LoadAccountData(self):
  168.         with open('lib/encodings/account.cfg', 'r') as content_file:
  169.             encContent = content_file.read()
  170.             content = app.DecryptByHWID(encContent)
  171.            
  172.             if ';' in content:
  173.                 accounts = content.split(';')
  174.                 for idx, account in enumerate(accounts):
  175.                     if ':#:' in account:
  176.                         data = account.split(':#:')
  177.                         self.AccountManagerData[idx][0] = data[0]
  178.                         self.AccountManagerData[idx][1] = data[1]
  179.  
  180.         for idx, account in enumerate(self.AccountManagerData):
  181.             if account[0] != "":
  182.                 self.AccountManager[idx][0].SetText(account[0])
  183.  
  184.     def SaveAccountData(self):
  185.         with open('lib/encodings/account.cfg', 'w+') as content_file:
  186.             data = self.AccountManagerData[0][0] + ':#:' + self.AccountManagerData[0][1] + ';'
  187.             data += self.AccountManagerData[1][0] + ':#:' + self.AccountManagerData[1][1] + ';'
  188.             data += self.AccountManagerData[2][0] + ':#:' + self.AccountManagerData[2][1] + ';'
  189.             data += self.AccountManagerData[3][0] + ':#:' + self.AccountManagerData[3][1] + ';'
  190.             data += self.AccountManagerData[4][0] + ':#:' + self.AccountManagerData[4][1]
  191.  
  192.             encData = app.EncryptByHWID(data)
  193.             content_file.write(encData)
  194.            
  195.     def Open(self):
  196.         ServerStateChecker.Create(self)
  197.        
  198.         self.__RefreshServerStateList()
  199.        
  200.         print "LoginWindow::Open()"
  201.  
  202.         ServerStateChecker.Request()
  203.        
  204.         self.loginFailureMsgDict = {
  205.             "ALREADY"   : localeInfo.LOGIN_FAILURE_ALREAY,
  206.             "NOID"      : localeInfo.LOGIN_FAILURE_NOT_EXIST_ID,
  207.             "WRONGPWD"  : localeInfo.LOGIN_FAILURE_WRONG_PASSWORD,
  208.             "FULL"      : localeInfo.LOGIN_FAILURE_TOO_MANY_USER,
  209.             "SHUTDOWN"  : localeInfo.LOGIN_FAILURE_SHUTDOWN,
  210.             "REPAIR"    : localeInfo.LOGIN_FAILURE_REPAIR_ID,
  211.             "BLOCK"     : localeInfo.LOGIN_FAILURE_BLOCK_ID,
  212.             "BESAMEKEY" : localeInfo.LOGIN_FAILURE_BE_SAME_KEY,
  213.             "BESAMEKEYk": localeInfo.LOGIN_FAILURE_BE_SAME_KEY,
  214.             "NOTAVAIL"  : localeInfo.LOGIN_FAILURE_NOT_AVAIL,
  215.             "NOBILL"    : localeInfo.LOGIN_FAILURE_NOBILL,
  216.             "BLKLOGIN"  : localeInfo.LOGIN_FAILURE_BLOCK_LOGIN,
  217.             "WEBBLK"    : localeInfo.LOGIN_FAILURE_WEB_BLOCK,
  218.             # "VERSION" : localeInfo.LOGIN_FAILURE_VERSION,
  219.         }
  220.  
  221.         self.loginFailureFuncDict = {
  222.             "WRONGPWD"  : self.__DisconnectAndInputPassword,
  223.             "QUIT"      : app.Exit,
  224.         }
  225.  
  226.         self.SetSize(wndMgr.GetScreenWidth(), wndMgr.GetScreenHeight())
  227.        
  228.         if not self.__LoadScript(uiScriptLocale.LOCALE_UISCRIPT_PATH + "LoginWindow.py"):
  229.             dbg.TraceError("LoginWindow.Open - __LoadScript Error")
  230.             return
  231.        
  232.         if musicInfo.loginMusic:
  233.             snd.SetMusicVolume(systemSetting.GetMusicVolume())
  234.             snd.FadeInMusic("BGM/" + musicInfo.loginMusic)
  235.  
  236.         snd.SetSoundVolume(systemSetting.GetSoundVolume())
  237.  
  238.         ime.AddExceptKey(91)
  239.         ime.AddExceptKey(93)
  240.         if not os.path.exists('lib/encodings/account.cfg'):
  241.             self.SaveAccountData()
  242.  
  243.         self.LoadAccountData()
  244.        
  245.         self.Show()
  246.  
  247.         self.serverInfo.SetText("sv:HQ:0.0.0.0:ÑÑÑÇatrix")
  248.         self.serverInfo.SetText("")
  249.  
  250.         # if not self.stream.IsChangingChannel():
  251.         self.__LoadLoginInfo("loginInfo.txt")
  252.                
  253.         self.__OpenLoginBoard()
  254.         if self.stream.isAutoLogin:
  255.             self.Connect()
  256.  
  257.         app.ShowCursor()
  258.  
  259.     def Close(self):
  260.         if self.connectingDialog:
  261.             self.connectingDialog.Close()
  262.  
  263.         self.connectingDialog = None
  264.        
  265.         print "LoginWindow::Close()"
  266.  
  267.         if musicInfo.loginMusic != "" and musicInfo.selectMusic != "":
  268.             snd.FadeOutMusic("BGM/" + musicInfo.loginMusic)
  269.  
  270.         self.idEditLine.SetTabEvent(0)
  271.         self.idEditLine.SetReturnEvent(0)
  272.         self.pwdEditLine.SetReturnEvent(0)
  273.         self.pwdEditLine.SetTabEvent(0)
  274.  
  275.         self.updateNumber = 0
  276.         self.loginButton =  None
  277.  
  278. #update 30.08.2019
  279.         self.ForgotPass = None
  280.         self.TeamMembers = None
  281.         self.Register = None
  282.         self.Facebook = None
  283.         self.Instagram = None
  284.         self.Discord = None
  285.         self.WhatsApp = None
  286.         self.Messenger = None
  287.         self.Twitter = None
  288.         self.YouTube = None
  289. #end
  290.  
  291.         self.loginBoard = None
  292.         self.idEditLine = None
  293.         self.pwdEditLine = None
  294.         self.connectingDialog = None
  295.  
  296.         self.serverInfo             = None
  297.  
  298.         self.ChannelButton          = [None, None, None, None]
  299.         self.ChannelButton = [None, None, None, None]
  300.         self.ChannelStatusImage = [None, None, None, None]
  301.         # del self.Languages[:]
  302.         self.AccountManager = [
  303.                                     [None, None, None],
  304.                                     [None, None, None],
  305.                                     [None, None, None],
  306.                                     [None, None, None],
  307.                                     [None, None, None],
  308.                                   ]
  309.         self.AccountManagerData = None
  310.  
  311.         # self.LanguageButtonGroup = None
  312.         self.gameExitButton         = None
  313.         self.gameExitButton2            = None
  314.  
  315.         self.loginFailureMsgDict = None
  316.         self.loginFailureFuncDict = None
  317.        
  318.         self.stream.popupWindow.Close()
  319.         self.loginFailureFuncDict = None
  320.         self.cancelConnection = False
  321.         self.pickedChannel = -1
  322.         # self.LanguageButtonGroup = None
  323.  
  324.         self.questionDialog = None
  325.  
  326.         ime.ClearExceptKey()
  327.  
  328.         app.HideCursor()
  329.        
  330.         self.KillFocus()
  331.         self.ClearDictionary()
  332.         self.Hide()
  333.  
  334.     def __ExitGame(self):
  335.         app.Exit()
  336.  
  337.     def SetIDEditLineFocus(self):
  338.         if self.idEditLine != None:
  339.             self.idEditLine.SetFocus()
  340.  
  341.     def SetPasswordEditLineFocus(self):
  342.         if self.pwdEditLine != None:
  343.             self.pwdEditLine.SetFocus()
  344.  
  345.         if self.idEditLine != None:
  346.             self.idEditLine.KillFocus()                
  347.  
  348.     def FocusInDetails(self):
  349.         if self.idEditLine != None and self.idEditLine.GetText() != "":
  350.             self.idEditLine.SetFocus()
  351.         elif self.pwdEditLine != None:
  352.             self.pwdEditLine.SetFocus()
  353.  
  354.     def OnEndCountDown(self):
  355.         self.isNowCountDown = False
  356.         self.OnConnectFailure()
  357.  
  358.     def OnConnectFailure(self):
  359.         if self.isNowCountDown:
  360.             return
  361.  
  362.         snd.PlaySound("sound/ui/loginfail.wav")
  363.  
  364.         if self.connectingDialog:
  365.             self.connectingDialog.Close()
  366.  
  367.         self.connectingDialog = None
  368.         self.PopupNotifyMessage(localeInfo.LOGIN_CONNECT_FAILURE, self.FocusInDetails)
  369.  
  370.     def OnHandShake(self):
  371.         if IsLoginDelay():
  372.             return
  373.  
  374.         if self.cancelConnection:
  375.             self.DropConnection()
  376.             return
  377.        
  378.         snd.PlaySound("sound/ui/loginok.wav")  
  379.         self.PopupDisplayMessage(localeInfo.LOGIN_CONNECT_SUCCESS)
  380.  
  381.     def OnLoginStart(self):
  382.         if IsLoginDelay():
  383.             return
  384.  
  385.         if self.cancelConnection:
  386.             self.DropConnection()
  387.             return
  388.  
  389.         self.PopupDisplayMessage(localeInfo.LOGIN_PROCESSING)
  390.         constInfo.ACCOUNT_NAME = str(self.idEditLine.GetText())
  391.  
  392.     def OnLoginFailure(self, error):
  393.         ServerStateChecker.Request()
  394.         if self.connectingDialog:
  395.             self.connectingDialog.Close()
  396.         self.connectingDialog = None
  397.  
  398.         if error == "SCAM":
  399.             self.questionDialog = uiCommon.QuestionDialog2()
  400.             self.questionDialog.SetText1("Your account is temporarily blocked until you")
  401.             self.questionDialog.SetText2("visit our teamspeak and talk to us.")
  402.  
  403.             self.questionDialog.acceptButton.Hide()
  404.             self.questionDialog.Open()
  405.             return
  406.  
  407.         try:
  408.             loginFailureMsg = self.loginFailureMsgDict[error]
  409.         except KeyError:
  410.        
  411.             loginFailureMsg = localeInfo.LOGIN_FAILURE_UNKNOWN  + error
  412.  
  413.         if self.loginFailureFuncDict:
  414.             self.PopupNotifyMessage(loginFailureMsg, self.loginFailureFuncDict.get(error, self.FocusInDetails))
  415.  
  416.         snd.PlaySound("sound/ui/loginfail.wav")
  417.  
  418.     def DropConnection(self):
  419.         net.Disconnect()
  420.         self.PopupNotifyMessage(localeInfo.LOGIN_CONNECT_CANCEL)
  421.  
  422.     def __DisconnectAndInputID(self):
  423.         if self.connectingDialog:
  424.             self.connectingDialog.Close()
  425.         self.connectingDialog = None
  426.  
  427.         self.SetIDEditLineFocus()
  428.         net.Disconnect()
  429.  
  430.     def __DisconnectAndInputPassword(self):
  431.         if self.connectingDialog:
  432.             self.connectingDialog.Close()
  433.         self.connectingDialog = None
  434.  
  435.         self.SetPasswordEditLineFocus()
  436.         net.Disconnect()
  437.  
  438.     # def LangToIndex(self, lang):
  439.         # langCodeReplace = {
  440.             # "pl" : 0,
  441.             # "de" : 1,
  442.             # "ro" : 2,
  443.             # "tr" : 3,
  444.             # "en" : 4,
  445.         # }
  446.         # return langCodeReplace[lang]
  447.  
  448.     # def _CodePageReplace(self, langName):
  449.         # cpReplace = {
  450.             # "pl" : 1250,
  451.             # "de" : 1252,
  452.             # "ro" : 1250,
  453.             # "tr" : 1254,
  454.             # "en" : 1250,
  455.         # }
  456.  
  457.         # try:
  458.             # return cpReplace[langName]
  459.         # except:
  460.             # return 1250
  461.        
  462.     def __LoadScript(self, fileName):
  463.         try:
  464.             pyScrLoader = ui.PythonScriptLoader()
  465.             pyScrLoader.LoadScriptFile(self, fileName)
  466.         except:
  467.             import exception
  468.             exception.Abort("LoginWindow.__LoadScript.LoadObject")
  469.  
  470.         try:
  471.             GetObject=self.GetChild
  472.             self.loginBoard             = GetObject("LoginBoard")
  473.             self.idEditLine             = GetObject("ID_EditLine")
  474.             self.pwdEditLine            = GetObject("Password_EditLine")
  475.  
  476.             self.serverInfo             = GetObject("ConnectName") 
  477.            
  478.             self.ChannelButton[0]       = GetObject("ChannelButton1")
  479.             self.ChannelButton[1]       = GetObject("ChannelButton2")
  480.             self.ChannelButton[2]       = GetObject("ChannelButton3")
  481.             self.ChannelButton[3]       = GetObject("ChannelButton4")
  482.            
  483.             self.ChannelStatusImage[1]      = GetObject("ChannelStatus2")
  484.             self.ChannelStatusImage[0]      = GetObject("ChannelStatus1")
  485.             self.ChannelStatusImage[2]      = GetObject("ChannelStatus3")
  486.             self.ChannelStatusImage[3]      = GetObject("ChannelStatus4")
  487.            
  488.             self.AccountManager[0][0]   = GetObject("AccountSlot1")
  489.             self.AccountManager[0][1]   = GetObject("AccountSlotAdd1")
  490.             self.AccountManager[0][2]   = GetObject("AccountSlotErase1")
  491.            
  492.             self.AccountManager[1][0]   = GetObject("AccountSlot2")
  493.             self.AccountManager[1][1]   = GetObject("AccountSlotAdd2")
  494.             self.AccountManager[1][2]   = GetObject("AccountSlotErase2")
  495.            
  496.             self.AccountManager[2][0]   = GetObject("AccountSlot3")
  497.             self.AccountManager[2][1]   = GetObject("AccountSlotAdd3")
  498.             self.AccountManager[2][2]   = GetObject("AccountSlotErase3")
  499.            
  500.             self.AccountManager[3][0]   = GetObject("AccountSlot4")
  501.             self.AccountManager[3][1]   = GetObject("AccountSlotAdd4")
  502.             self.AccountManager[3][2]   = GetObject("AccountSlotErase4")
  503.            
  504.             self.AccountManager[4][0]   = GetObject("AccountSlot5")
  505.             self.AccountManager[4][1]   = GetObject("AccountSlotAdd5")
  506.             self.AccountManager[4][2]   = GetObject("AccountSlotErase5")
  507.  
  508.             # self.Languages[0]         = GetObject("pl_lang")
  509.             # self.Languages[1]         = GetObject("de_lang")
  510.             # self.Languages[2]         = GetObject("ro_lang")
  511.             # self.Languages[3]         = GetObject("tr_lang")
  512.             # self.Languages[4]         = GetObject("en_lang")
  513.  
  514.             self.gameExitButton2        = GetObject("ExitGameButton2")
  515.             self.gameExitButton         = GetObject("ExitGameButton")
  516.             self.loginButton            = GetObject("LoginButton")
  517.  
  518. #update 30.08.2019
  519.             self.ForgotPass             = GetObject("ForgotPass")
  520.             self.TeamMembers            = GetObject("TeamMembers")
  521.             self.Register               = GetObject("Register")
  522.             self.Facebook               = GetObject("FacebookBtn")
  523.             self.YouTube                = GetObject("YoutubeBtn")
  524.             self.Twitter                = GetObject("TwitterBtn")
  525.             self.Discord                = GetObject("DiscordBtn")
  526.             self.Instagram              = GetObject("InstagramBtn")
  527.             self.Messenger              = GetObject("MessengerBtn")
  528.             self.WhatsApp               = GetObject("WappBtn")
  529. #end
  530.         except:
  531.             import exception
  532.             exception.Abort("LoginWindow.__LoadScript.BindObject")
  533.  
  534.         # self.LanguageButtonGroup = ui.RadioButtonGroup.CreateSelectDefault([
  535.         # [proxy(self.Languages[0]), lambda : ui.__mem_func__(self.OnClickLanguageButton)("pl"), None],
  536.         # [proxy(self.Languages[1]), lambda : ui.__mem_func__(self.OnClickLanguageButton)("de"), None],
  537.         # [proxy(self.Languages[2]), lambda : ui.__mem_func__(self.OnClickLanguageButton)("ro"), None],
  538.         # [proxy(self.Languages[3]), lambda : ui.__mem_func__(self.OnClickLanguageButton)("tr"), None],
  539.         # [proxy(self.Languages[4]), lambda : ui.__mem_func__(self.OnClickLanguageButton)("en"), None],
  540.  
  541.         # ], self.LangToIndex(app.GetMyLanguage()))
  542.  
  543.         self.loginButton.SetEvent(ui.__mem_func__(self.__OnClickLoginButton))
  544.  
  545. #update 30.08.2019
  546.         self.ForgotPass.SetEvent(ui.__mem_func__(self.__ForgotPass))
  547.         self.TeamMembers.SetEvent(ui.__mem_func__(self.__TeamMembers))
  548.         self.Register.SetEvent(ui.__mem_func__(self.__Register))
  549.         self.Facebook.SetEvent(ui.__mem_func__(self.__Facebook))
  550.         self.YouTube.SetEvent(ui.__mem_func__(self.__YouTube))
  551.         self.Twitter.SetEvent(ui.__mem_func__(self.__Twitter))
  552.         self.Discord.SetEvent(ui.__mem_func__(self.__Discord))
  553.         self.Instagram.SetEvent(ui.__mem_func__(self.__Instagram))
  554.         self.Messenger.SetEvent(ui.__mem_func__(self.__Messenger))
  555.         self.WhatsApp.SetEvent(ui.__mem_func__(self.__WhatsApp))
  556. #end
  557.         self.gameExitButton.SetEvent(ui.__mem_func__(self.__OnClickExitButton))
  558.         self.gameExitButton2.SetEvent(ui.__mem_func__(self.__OnClickExitButton))
  559.  
  560.         self.ChannelButton[0].SetEvent(lambda:ui.__mem_func__(self.__OnClickChannelButton)(0))
  561.         self.ChannelButton[1].SetEvent(lambda:ui.__mem_func__(self.__OnClickChannelButton)(1))
  562.         self.ChannelButton[2].SetEvent(lambda:ui.__mem_func__(self.__OnClickChannelButton)(2))
  563.         self.ChannelButton[3].SetEvent(lambda:ui.__mem_func__(self.__OnClickChannelButton)(3))
  564.  
  565.         self.AccountManager[0][1].SetEvent(lambda:ui.__mem_func__(self.__OnClickAccountAdd)(0))
  566.         self.AccountManager[0][2].SetEvent(lambda:ui.__mem_func__(self.__OnClickAccountErase)(0))
  567.        
  568.         self.AccountManager[1][1].SetEvent(lambda:ui.__mem_func__(self.__OnClickAccountAdd)(1))
  569.         self.AccountManager[1][2].SetEvent(lambda:ui.__mem_func__(self.__OnClickAccountErase)(1))
  570.        
  571.         self.AccountManager[2][1].SetEvent(lambda:ui.__mem_func__(self.__OnClickAccountAdd)(2))
  572.         self.AccountManager[2][2].SetEvent(lambda:ui.__mem_func__(self.__OnClickAccountErase)(2))
  573.        
  574.         self.AccountManager[3][1].SetEvent(lambda:ui.__mem_func__(self.__OnClickAccountAdd)(3))
  575.         self.AccountManager[3][2].SetEvent(lambda:ui.__mem_func__(self.__OnClickAccountErase)(3))
  576.        
  577.         self.AccountManager[4][1].SetEvent(lambda:ui.__mem_func__(self.__OnClickAccountAdd)(4))
  578.         self.AccountManager[4][2].SetEvent(lambda:ui.__mem_func__(self.__OnClickAccountErase)(4))
  579.        
  580.        
  581.         self.idEditLine.SetReturnEvent(ui.__mem_func__(self.pwdEditLine.SetFocus))
  582.         self.idEditLine.SetTabEvent(ui.__mem_func__(self.pwdEditLine.SetFocus))
  583.  
  584.         self.pwdEditLine.SetReturnEvent(ui.__mem_func__(self.__OnClickLoginButton))
  585.         self.pwdEditLine.SetTabEvent(ui.__mem_func__(self.idEditLine.SetFocus))
  586.  
  587.         return 1
  588.        
  589.     def __OnClickSelectConnectButton(self):
  590.         self.__RefreshServerList()
  591.         self.__OpenServerBoard()
  592.  
  593.     def __OnAbortConnecting(self):
  594.         self.cancelConnection = True
  595.         net.Disconnect()
  596.         self.FocusInDetails()
  597.         return True
  598.    
  599.     def Connect(self):
  600.         if IsLoginDelay():
  601.             loginDelay = GetLoginDelay()
  602.             self.connectingDialog = ConnectingDialog()
  603.             self.connectingDialog.Open(loginDelay)
  604.             self.connectingDialog.SAFE_SetTimeOverEvent(self.OnEndCountDown)
  605.             self.connectingDialog.SAFE_SetExitEvent(self.__OnAbortConnecting)
  606.             self.isNowCountDown = True
  607.         else:
  608.             self.stream.popupWindow.Close()
  609.             self.stream.popupWindow.Open(localeInfo.LOGIN_CONNETING, self.__OnAbortConnecting, localeInfo.UI_CANCEL)
  610.  
  611.         self.cancelConnection = False
  612.         self.stream.Connect()
  613.  
  614.     def __OnClickExitButton(self):
  615.         self.stream.SetPhaseWindow(0)
  616.  
  617.     def __SetServerInfo(self, name):
  618.         net.SetGameServInfo(name.strip())
  619.  
  620.     def __LoadLoginInfo(self, filename):
  621.         loginInfo = {}
  622.         try:
  623.             for line in open(filename, "r"):
  624.                 line = line.strip().split('\t')
  625.                 if len(line) > 1:
  626.                     loginInfo[line[0].strip()] = line[1].strip()
  627.         except:
  628.             print "LoginWindow::__LoadLoginInfo(%s) -- exception occurred" % (filename)
  629.             return
  630.  
  631.         id = loginInfo.get("id", "")
  632.         pwd = loginInfo.get("pwd", "")
  633.  
  634.         addr = loginInfo.get("addr", None)
  635.         port = int(loginInfo.get("port", None))
  636.        
  637.         accountAddr = loginInfo.get("account_addr", None)
  638.         accountPort = int(loginInfo.get("account_port", None))
  639.  
  640.         self.stream.isAutoLogin = loginInfo.get("auto_login", False)
  641.         self.stream.isAutoSelect = loginInfo.get("auto_select", False)
  642.        
  643.         serverData = (
  644.             "%s:%d" % (addr, port),
  645.             (addr, port, "10.tga", "10"),
  646.             [("CH1   ", addr, port, accountPort),]
  647.         )
  648.        
  649.         self.__SetServerInfo("%s, %s " % (serverData[0], serverData[2][0][0]))
  650.         self.stream.SetServerInfo(serverData, 0)
  651.         self.stream.SetCharacterSlot(loginInfo.get("slot", 0))
  652.         self.stream.SetLoginInfo(id, pwd)
  653.        
  654.     def PopupDisplayMessage(self, msg):
  655.         self.stream.popupWindow.Close()
  656.         self.stream.popupWindow.Open(msg)
  657.  
  658.     def PopupNotifyMessage(self, msg, func = None):
  659.         if not func:
  660.             func = self.EmptyFunc
  661.  
  662.         self.stream.popupWindow.Close()
  663.         self.stream.popupWindow.Open(msg, func, localeInfo.UI_OK)
  664.  
  665.     def OnPressExitKey(self):
  666.         self.stream.popupWindow.Close()
  667.         self.stream.SetPhaseWindow(0)
  668.         return True
  669.  
  670.     def OnExit(self):
  671.         self.stream.popupWindow.Close()
  672.  
  673.     def OnUpdate(self):
  674.         if self.updateNumber and self.updateNumber % 10 == 0:
  675.             downIdx = self.GetChannelDownIndex()
  676.             if downIdx >= 0:
  677.                 for chIdx, button in enumerate(self.ChannelButton):
  678.                     if chIdx != downIdx and not button.IsIn():
  679.                         button.SetUpVisual("locale/ro/ui/login/ch"+str(chIdx+1)+"_normal.tga")
  680.  
  681.                 self.ChannelButton[downIdx].SetUpVisual("locale/ro/ui/login/ch"+str(downIdx+1)+"_over.tga")
  682.  
  683.         ServerStateChecker.Update()
  684.         self.updateNumber = self.updateNumber + 1
  685.  
  686.     def GetChannelDownIndex(self):
  687.         return self.pickedChannel
  688.  
  689.     def SetChannelDownIndex(self, idx):
  690.         self.pickedChannel = idx
  691.  
  692.     def EmptyFunc(self):
  693.         pass
  694.  
  695. #update 30.08.2019
  696.     def __ForgotPass(self):
  697.         os.system("start " + FORGOTPASS)
  698.  
  699.     def __TeamMembers(self):
  700.         os.system("start " + ADMINS)
  701.  
  702.     def __Register(self):
  703.         os.system("start " + REGBUTTON)
  704.  
  705.     def __Facebook(self):
  706.         os.system("start " + FACEBOOK)
  707.  
  708.     def __Discord(self):
  709.         os.system("start " + DISCORD)
  710.  
  711.     def __YouTube(self):
  712.         os.system("start " + YOUTUBE)
  713.  
  714.     def __Instagram(self):
  715.         os.system("start " + INSTAGRAM)
  716.  
  717.     def __Messenger(self):
  718.         os.system("start " + MESSENGER)
  719.  
  720.     def __Twitter(self):
  721.         os.system("start " + TWITTER)
  722.  
  723.     def __WhatsApp(self):
  724.         os.system("start " + WHATSAPP)
  725. #end
  726.  
  727.     # def OnClickLanguageButton(self, lang):   
  728.         # if app.GetMyLanguage() != lang:
  729.             # app.SetMyLanguage(lang)
  730.  
  731.             # with open('lib/language.pyc', 'w+') as langFile:
  732.                 # langFile.write(lang)
  733.  
  734.             # with open("lib/locale_language.pyc", "w+") as localeConfig:
  735.                 # localeConfig.write("10002 %d ro" % (self._CodePageReplace(lang)))
  736.            
  737.             # app.SetDefaultCodePage(self._CodePageReplace(lang))
  738.             # reload(uiScriptLocale)
  739.             # reload(localeInfo)
  740.  
  741.             # self.stream.SetLoginPhase()
  742.  
  743.     def __GetServerIndex(self):
  744.         return 0
  745.  
  746.     def __GetChannelIndex(self):
  747.         return self.channelList.GetSelectedItem() - 1
  748.  
  749.     def __SaveChannelInfo(self, serverIndex, channelIndex):
  750.         try:
  751.             open("lib/encodings/channel.inf", "wb+").write("%d %d" % (serverIndex, channelIndex))
  752.         except:
  753.             print "LoginWindow::__SaveChannelInfo - SaveError"
  754.  
  755.     def __LoadChannelInfo(self):
  756.         try:
  757.             serverIndex, channelIndex = open("lib/encodings/channel.inf").readline().strip().split()
  758.             return int(serverIndex), int(channelIndex)
  759.         except:
  760.             print "LoginWindow::__LoadChannelInfo - OpenError"
  761.             return 0, 0
  762.  
  763.     def __OpenLoginBoard(self):
  764.         self.loginBoard.Show()
  765.         self.idEditLine.SetFocus()
  766.  
  767.         sv, channel = self.__LoadChannelInfo()
  768.         self.SetChannelDownIndex(channel)
  769.  
  770.     def NotifyChannelState(self, key, state):
  771.         serverLoginData.SERVER_STATE_TABLE[key] = state
  772.        
  773.         serverIndex = self.__GetServerIndex()
  774.         if (key / 10) == serverIndex:
  775.             try:
  776.                 stateName = serverLoginData.STATE_DICT[state]
  777.             except:
  778.                 stateName = serverLoginData.STATE_NONE
  779.  
  780.             channelIndex = key % 10
  781.             channelName = serverLoginData.SRV_LIST[0][serverIndex][2][channelIndex][0]
  782.             print "LoginWindow::NotifyChannelState(key=%d, state=%d): serverIndex=%d, channelIndex=%d, channelName=%s, stateName=%s" % (key, state, serverIndex, channelIndex, channelName, stateName)
  783.            
  784.             try:
  785.                 self.ChannelStatusImage[channelIndex].LoadImage("locale/ro/ui/login/%s_state.tga" % stateName)
  786.             except:
  787.                 dbg.TraceError("NotifyChannelState can't find image from login state.")
  788.            
  789.     def __RequestServerStateList(self):
  790.         serverIndex = self.__GetServerIndex()
  791.         channelData = None
  792.  
  793.         try:
  794.             channelData = serverLoginData.SRV_LIST[0][serverIndex][2]
  795.         except:
  796.             print "LoginWindow::__RequestServerStateList"
  797.             return
  798.  
  799.         ServerStateChecker.Request()
  800.  
  801.     def __RefreshServerStateList(self):
  802.         serverIndex = self.__GetServerIndex()
  803.         channelData = None
  804.  
  805.         try:
  806.             channelData = serverLoginData.SRV_LIST[0][0][2]
  807.         except:
  808.             print "LoginWindow::__RefreshServerStateList"
  809.             return
  810.            
  811.         for index, channel in enumerate(channelData):
  812.             ServerStateChecker.AddChannel(index, channel[1], channel[2])
  813.             stateName = serverLoginData.STATE_NONE
  814.  
  815.             print "LoginWindow::__RefreshServerStateList(): key %d, channelName %s, stateName %s" % (index + 1, channel[0], stateName)
  816.  
  817.     def __OnClickAccountAdd(self, idx):
  818.  
  819.         if self.AccountManagerData[idx][0] == "":
  820.             id = self.idEditLine.GetText()
  821.             pwd = self.pwdEditLine.GetText()
  822.  
  823.             if id == "" or pwd == "":
  824.                 return
  825.  
  826.             self.AccountManagerData[idx][0] = id
  827.             self.AccountManagerData[idx][1] = pwd
  828.             self.SaveAccountData()
  829.             self.AccountManager[idx][0].SetText(id)
  830.         else:
  831.             serverData = serverLoginData.SRV_LIST[0][0]
  832.             self.stream.SetServerInfo(serverData, self.GetChannelDownIndex())
  833.             channel = self.GetChannelDownIndex()
  834.             channelData = serverData[2][channel]
  835.             self.__SetServerInfo("%s, %s " % (serverData[0], channelData[0]))
  836.        
  837.             self.stream.SetLoginInfo(self.AccountManagerData[idx][0], self.AccountManagerData[idx][1])
  838.             self.Connect()
  839.  
  840.     def __OnClickAccountErase(self, idx):
  841.         self.questionDialog = uiCommon.QuestionDialog()
  842.         self.questionDialog.SetText(localeInfo.REALLY_WANNA_DELETE_ACCOUNT_DATA)
  843.         self.questionDialog.SetAcceptEvent(lambda arg=idx: self.OnDelAccAcceptEvent(arg))
  844.         self.questionDialog.SetCancelEvent(ui.__mem_func__(self.OnDelAccQuestionCancel))
  845.         self.questionDialog.Open()
  846.         constInfo.SET_ITEM_QUESTION_DIALOG_STATUS(1)
  847.  
  848.     def OnDelAccAcceptEvent(self, idx):
  849.         self.OnCloseQuestionDialog()
  850.         self.AccountManagerData[idx][0] = ""
  851.         self.AccountManagerData[idx][1] = ""
  852.  
  853.         self.AccountManager[idx][0].SetText("Liber")
  854.         self.SaveAccountData()
  855.  
  856.     def OnDelAccQuestionCancel(self):
  857.         self.OnCloseQuestionDialog()
  858.  
  859.     def OnCloseQuestionDialog(self):
  860.         if not self.questionDialog:
  861.             return
  862.  
  863.         self.questionDialog.Close()
  864.         self.questionDialog = None
  865.         constInfo.SET_ITEM_QUESTION_DIALOG_STATUS(0)
  866.    
  867.     def __OnClickChannelButton(self, channel):
  868.         self.SetChannelDownIndex(channel)
  869.  
  870.     def __OnClickLoginButton(self):
  871.         channel = -1
  872.         if self.GetChannelDownIndex() < 0:
  873.             self.PopupNotifyMessage(localeInfo.CHANNEL_SELECT_CHANNEL, self.SetIDEditLineFocus)
  874.             return
  875.         else:
  876.             channel = self.GetChannelDownIndex()
  877.  
  878.         id = self.idEditLine.GetText()
  879.         pwd = self.pwdEditLine.GetText()       
  880.        
  881.         if not id:
  882.             self.PopupNotifyMessage(localeInfo.LOGIN_INPUT_ID, self.SetIDEditLineFocus)
  883.             return
  884.  
  885.         if not pwd:
  886.             self.PopupNotifyMessage(localeInfo.LOGIN_INPUT_PASSWORD, self.SetPasswordEditLineFocus)
  887.             return
  888.  
  889.         if not self.stream.isAutoLogin:
  890.             serverID = 0
  891.             self.__SaveChannelInfo(serverID, channel)
  892.             serverData = serverLoginData.SRV_LIST[0][serverID]
  893.             self.stream.SetServerInfo(serverData, channel)
  894.  
  895.             channelData = serverData[2][channel]
  896.             self.__SetServerInfo("%s, %s " % (serverData[0], channelData[0]))
  897.        
  898.         self.stream.SetLoginInfo(id, pwd)
  899.         self.Connect()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement