1. import app
  2. import net
  3. import ui
  4. import snd
  5. import wndMgr
  6. import musicInfo
  7. import systemSetting
  8. import localeInfo
  9. import constInfo
  10. import ime
  11. import uiScriptLocale
  12. ''' codin' pass '''
  13. import binascii
  14. ''' Registry '''
  15. import _winreg
  16. REG_PATH = r"SOFTWARE\VegaS"
  17. def set_vegas(name, value):
  18. try:
  19. _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, REG_PATH)
  20. registry_key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, REG_PATH, 0,
  21. _winreg.KEY_WRITE)
  22. _winreg.SetValueEx(registry_key, name, 0, _winreg.REG_SZ, value)
  23. _winreg.CloseKey(registry_key)
  24. return True
  25. except WindowsError:
  26. return False
  27. def get_vegas(name):
  28. try:
  29. registry_key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, REG_PATH, 0,
  30. _winreg.KEY_READ)
  31. value, regtype = _winreg.QueryValueEx(registry_key, name)
  32. _winreg.CloseKey(registry_key)
  33. return value
  34. except WindowsError:
  35. return None
  36. class LoginWindow(ui.ScriptWindow):
  37. IS_TEST = net.IsTest()
  38. def __init__(self, stream):
  39. ui.ScriptWindow.__init__(self)
  40. net.SetPhaseWindow(net.PHASE_WINDOW_LOGIN, self)
  41. net.SetAccountConnectorHandler(self)
  42. self.stream = stream
  43. self.channels = 0
  44. self.channelButton = None
  45. self.panelButton = None
  46. def __del__(self):
  47. ui.ScriptWindow.__del__(self)
  48. net.ClearPhaseWindow(net.PHASE_WINDOW_LOGIN, self)
  49. net.SetAccountConnectorHandler(0)
  50. def Open(self):
  51. self.loginFailureMsgDict={
  52. "ALREADY" : localeInfo.LOGIN_FAILURE_ALREAY,
  53. "NOID" : localeInfo.LOGIN_FAILURE_NOT_EXIST_ID,
  54. "WRONGPWD" : localeInfo.LOGIN_FAILURE_WRONG_PASSWORD,
  55. "FULL" : localeInfo.LOGIN_FAILURE_TOO_MANY_USER,
  56. "SHUTDOWN" : localeInfo.LOGIN_FAILURE_SHUTDOWN,
  57. "REPAIR" : localeInfo.LOGIN_FAILURE_REPAIR_ID,
  58. "BLOCK" : localeInfo.LOGIN_FAILURE_BLOCK_ID,
  59. "WRONGMAT" : localeInfo.LOGIN_FAILURE_WRONG_MATRIX_CARD_NUMBER,
  60. "QUIT" : localeInfo.LOGIN_FAILURE_WRONG_MATRIX_CARD_NUMBER_TRIPLE,
  61. "BESAMEKEY" : localeInfo.LOGIN_FAILURE_BE_SAME_KEY,
  62. "NOTAVAIL" : localeInfo.LOGIN_FAILURE_NOT_AVAIL,
  63. "NOBILL" : localeInfo.LOGIN_FAILURE_NOBILL,
  64. "BLKLOGIN" : localeInfo.LOGIN_FAILURE_BLOCK_LOGIN,
  65. "WEBBLK" : localeInfo.LOGIN_FAILURE_WEB_BLOCK,
  66. }
  67. self.loginFailureFuncDict = {
  68. "WRONGPWD" : localeInfo.LOGIN_FAILURE_WRONG_PASSWORD,
  69. "WRONGMAT" : localeInfo.LOGIN_FAILURE_WRONG_MATRIX_CARD_NUMBER,
  70. "QUIT" : app.Exit,
  71. }
  72. self.SetSize(wndMgr.GetScreenWidth(), wndMgr.GetScreenHeight())
  73. self.SetWindowName("LoginWindow")
  74. self.__LoadScript(uiScriptLocale.LOCALE_UISCRIPT_PATH + "LoginWindow.py")
  75. if musicInfo.loginMusic != "":
  76. snd.SetMusicVolume(systemSetting.GetMusicVolume())
  77. snd.FadeInMusic("BGM/" + musicInfo.loginMusic)
  78. snd.SetSoundVolume(systemSetting.GetSoundVolume())
  79. ime.AddExceptKey(91)
  80. ime.AddExceptKey(93)
  81. self.SetChannelKurwy("CH1")
  82. self.idEditLine.SetFocus()
  83. self.Show()
  84. app.ShowCursor()
  85. def Close(self):
  86. if musicInfo.loginMusic != "" and musicInfo.selectMusic != "":
  87. snd.FadeOutMusic("BGM/"+musicInfo.loginMusic)
  88. if self.stream.popupWindow:
  89. self.stream.popupWindow.Close()
  90. self.Hide()
  91. app.HideCursor()
  92. ime.ClearExceptKey()
  93. def OnConnectFailure(self):
  94. snd.PlaySound("sound/ui/loginfail.wav")
  95. self.PopupNotifyMessage(localeInfo.LOGIN_CONNECT_FAILURE, self.EmptyFunc)
  96. def OnHandShake(self):
  97. snd.PlaySound("sound/ui/loginok.wav")
  98. self.PopupDisplayMessage(localeInfo.LOGIN_CONNECT_SUCCESS)
  99. def OnLoginStart(self):
  100. self.PopupDisplayMessage(localeInfo.LOGIN_PROCESSING)
  101. def OnLoginFailure(self, error):
  102. try:
  103. loginFailureMsg = self.loginFailureMsgDict[error]
  104. except KeyError:
  105. loginFailureMsg = localeInfo.LOGIN_FAILURE_UNKNOWN + error
  106. loginFailureFunc = self.loginFailureFuncDict.get(error, self.EmptyFunc)
  107. self.PopupNotifyMessage(loginFailureMsg, loginFailureFunc)
  108. snd.PlaySound("sound/ui/loginfail.wav")
  109. def __LoadScript(self, fileName):
  110. try:
  111. pyScrLoader = ui.PythonScriptLoader()
  112. pyScrLoader.LoadScriptFile(self, fileName)
  113. except:
  114. import exception
  115. exception.Abort("LoginWindow.__LoadScript.LoadObject")
  116. try:
  117. self.idEditLine = self.GetChild("id")
  118. self.pwdEditLine = self.GetChild("pwd")
  119. self.loginButton = self.GetChild("enter")
  120. self.channelButton = {
  121. "CH1" : self.GetChild("ch1"),
  122. "CH2" : self.GetChild("ch2"),
  123. "CH3" : self.GetChild("ch3"),
  124. "CH4" : self.GetChild("ch4"),
  125. "CH5" : self.GetChild("ch5"),
  126. "CH6" : self.GetChild("ch6")}
  127. self.panelButton = {
  128. "EXIT" : self.GetChild("exit")}
  129. for (action, button) in self.panelButton.items():
  130. button.SetEvent(ui.__mem_func__(self.MainBoard), action)
  131. for (channelID, channelButtons) in self.channelButton.items():
  132. channelButtons.SetEvent(ui.__mem_func__(self.SetChannelKurwy), channelID)
  133. if (get_vegas("id") != None) and (get_vegas("pwd") != None):
  134. self.idEditLine.SetText("%s" % binascii.a2b_base64("%s" % get_vegas("id")))
  135. self.pwdEditLine.SetText("%s" % binascii.a2b_base64("%s" % get_vegas("pwd")))
  136. except:
  137. import exception
  138. exception.Abort("LoginWindow.__LoadScript.BindObject")
  139. self.loginButton.SetEvent(ui.__mem_func__(self.__OnClickLoginButton))
  140. self.idEditLine.SetReturnEvent(ui.__mem_func__(self.pwdEditLine.SetFocus))
  141. self.idEditLine.SetTabEvent(ui.__mem_func__(self.pwdEditLine.SetFocus))
  142. self.pwdEditLine.SetReturnEvent(ui.__mem_func__(self.__OnClickLoginButton))
  143. self.pwdEditLine.SetTabEvent(ui.__mem_func__(self.idEditLine.SetFocus))
  144. def MainBoard(self, action):
  145. actions = {
  146. "EXIT" : 0}
  147. if actions.has_key(action):
  148. if action != "EXIT":
  149. pass
  150. else:
  151. self.stream.SetPhaseWindow(0)
  152. def SetChannelKurwy(self, ch):
  153. self.SetChannelInfo(ch)
  154. for (channelID, channelButtons) in self.channelButton.items():
  155. if ch != channelID:
  156. channelButtons.SetUp()
  157. self.stream.SetConnectInfo("188.212.103.219", self.ChannelPort(ch, 0), "188.212.103.219", self.ChannelPort("LOGIN"))
  158. net.SetMarkServer("188.212.103.219", self.ChannelPort("LOGO"))
  159. app.SetGuildMarkPath("10.tga")
  160. app.SetGuildSymbolPath("10")
  161. net.SetServerInfo(self.ChannelPort(ch, 2))
  162. def SetChannelInfo(self, ch):
  163. self.channels = str(ch)
  164. def GetChannel(self):
  165. return self.channels
  166. def ChannelPort(self, ch="CH1", value=0):
  167. channel = {
  168. "CH1" : [21000, "ROG II -", "CH 1"],
  169. "CH2" : [22000, "ROG II -", "CH 2"],
  170. "CH3" : [24000, "ROG II -", "CH 3"],
  171. "CH4" : [25000, "ROG II -", "CH 4"],
  172. "CH5" : [21000, "ROG II -", "CH 5"],
  173. "CH6" : [21000, "ROG II -", "CH 6"]}
  174. if ch == "LOGIN":
  175. return 31009
  176. elif ch == "LOGO":
  177. return channel["CH1"][0]
  178. elif value == 2:
  179. return "%s, %s" % (channel[ch][1], channel[ch][2])
  180. else:
  181. return channel[ch][value]
  182. def Connect(self, id, pwd):
  183. if constInfo.SEQUENCE_PACKET_ENABLE:
  184. net.SetPacketSequenceMode()
  185. self.stream.popupWindow.Close()
  186. self.stream.popupWindow.Open(localeInfo.LOGIN_CONNETING, self.EmptyFunc, localeInfo.UI_CANCEL)
  187. self.stream.SetLoginInfo(id, pwd)
  188. self.stream.Connect()
  189. def PopupDisplayMessage(self, msg):
  190. self.stream.popupWindow.Close()
  191. self.stream.popupWindow.Open(msg)
  192. def PopupNotifyMessage(self, msg, func=0):
  193. if not func:
  194. func = self.EmptyFunc
  195. self.stream.popupWindow.Close()
  196. self.stream.popupWindow.Open(msg, func, localeInfo.UI_OK)
  197. def OnPressExitKey(self):
  198. if self.stream.popupWindow:
  199. self.stream.popupWindow.Close()
  200. self.stream.SetPhaseWindow(0)
  201. return TRUE
  202. def OnUpdate(self):
  203. for (channelID, channelButtons) in self.channelButton.items():
  204. if self.GetChannel() == channelID:
  205. channelButtons.Down()
  206. def EmptyFunc(self):
  207. pass
  208. def __OnClickLoginButton(self):
  209. id = self.idEditLine.GetText()
  210. pwd = self.pwdEditLine.GetText()
  211. if len(id)==0:
  212. self.PopupNotifyMessage(localeInfo.LOGIN_INPUT_ID, self.EmptyFunc)
  213. return
  214. if len(pwd)==0:
  215. self.PopupNotifyMessage(localeInfo.LOGIN_INPUT_PASSWORD, self.EmptyFunc)
  216. return
  217. set_vegas("id", str(binascii.b2a_base64(id)))
  218. set_vegas("pwd", str(binascii.b2a_base64(pwd)))
  219. self.Connect(id, pwd)

intrologin.py