Guest User

networkmodule.py

a guest
May 14th, 2020
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.93 KB | None | 0 0
  1. ###################################################################################################
  2. # Network
  3.  
  4. import app
  5. import chr
  6. import dbg
  7. import net
  8. import snd
  9.  
  10. import chr
  11. import chrmgr
  12. import background
  13. import player
  14. import playerSettingModule
  15.  
  16. import ui
  17. import uiPhaseCurtain
  18.  
  19. import localeInfo
  20.  
  21. class PopupDialog(ui.ScriptWindow):
  22.  
  23.     def __init__(self):
  24.         print "NEW POPUP DIALOG ----------------------------------------------------------------------------"
  25.         ui.ScriptWindow.__init__(self)
  26.         self.CloseEvent = 0
  27.  
  28.     def __del__(self):
  29.         print "---------------------------------------------------------------------------- DELETE POPUP DIALOG "
  30.         ui.ScriptWindow.__del__(self)
  31.  
  32.     def LoadDialog(self):
  33.         PythonScriptLoader = ui.PythonScriptLoader()
  34.         PythonScriptLoader.LoadScriptFile(self, "UIScript/PopupDialog.py")
  35.  
  36.     def Open(self, Message, event = 0, ButtonName = localeInfo.UI_CANCEL):
  37.  
  38.         if TRUE == self.IsShow():
  39.             self.Close()
  40.  
  41.         self.Lock()
  42.         self.SetTop()
  43.         self.CloseEvent = event
  44.  
  45.         AcceptButton = self.GetChild("accept")
  46.         AcceptButton.SetText(ButtonName)
  47.         AcceptButton.SetEvent(ui.__mem_func__(self.Close))
  48.  
  49.         self.GetChild("message").SetText(Message)
  50.         self.Show()
  51.  
  52.     def Close(self):
  53.  
  54.         if FALSE == self.IsShow():
  55.             self.CloseEvent = 0
  56.             return
  57.  
  58.         self.Unlock()
  59.         self.Hide()
  60.  
  61.         if 0 != self.CloseEvent:
  62.             self.CloseEvent()
  63.             self.CloseEvent = 0
  64.  
  65.     def Destroy(self):
  66.         self.Close()
  67.         self.ClearDictionary()
  68.  
  69.     def OnPressEscapeKey(self):
  70.         self.Close()
  71.         return TRUE
  72.  
  73.     def OnIMEReturn(self):
  74.         self.Close()
  75.         return TRUE
  76.  
  77. ##
  78. ## Main Stream
  79. ##
  80. class MainStream(object):
  81.     isChrData=0
  82.  
  83.     def __init__(self):
  84.         print "NEWMAIN STREAM ----------------------------------------------------------------------------"
  85.         net.SetHandler(self)
  86.         net.SetTCPRecvBufferSize(128*1024)
  87.         net.SetTCPSendBufferSize(4096)
  88.  
  89.         self.id=""
  90.         self.pwd=""
  91.         self.addr=""
  92.         self.port=0
  93.         self.account_addr=0
  94.         self.account_port=0
  95.         self.slot=0
  96.         self.isAutoSelect=0
  97.         self.isAutoLogin=0
  98.        
  99.         self.serverInfo = None
  100.         self.channelIndex = 0
  101.  
  102.         self.curtain = 0
  103.         self.curPhaseWindow = 0
  104.         self.newPhaseWindow = 0
  105.  
  106.     def __del__(self):
  107.         print "---------------------------------------------------------------------------- DELETE MAIN STREAM "
  108.  
  109.     def Destroy(self):
  110.         if self.curPhaseWindow:
  111.             self.curPhaseWindow.Close()
  112.             self.curPhaseWindow = 0
  113.  
  114.         if self.newPhaseWindow:
  115.             self.newPhaseWindow.Close()
  116.             self.newPhaseWindow = 0
  117.  
  118.         self.popupWindow.Destroy()
  119.         self.popupWindow = 0
  120.  
  121.         self.curtain = 0
  122.  
  123.     def Create(self):
  124.         self.CreatePopupDialog()
  125.  
  126.         self.curtain = uiPhaseCurtain.PhaseCurtain()
  127.  
  128.     def SetPhaseWindow(self, newPhaseWindow):
  129.         if self.newPhaseWindow:
  130.             #print "이미 새로운 윈도우로 바꾼상태에서 또 바꿈", newPhaseWindow
  131.             self.__ChangePhaseWindow()
  132.  
  133.         self.newPhaseWindow=newPhaseWindow
  134.  
  135.         if self.curPhaseWindow:
  136.             #print "페이드 아웃되면 바꿈"
  137.             self.curtain.FadeOut(self.__ChangePhaseWindow)
  138.         else:
  139.             #print "현재 윈도우가 없는 상태라 바로 바꿈"
  140.             self.__ChangePhaseWindow()
  141.  
  142.     def __ChangePhaseWindow(self):
  143.         oldPhaseWindow=self.curPhaseWindow
  144.         newPhaseWindow=self.newPhaseWindow
  145.         self.curPhaseWindow=0
  146.         self.newPhaseWindow=0
  147.  
  148.         if oldPhaseWindow:
  149.             oldPhaseWindow.Close()
  150.  
  151.         if newPhaseWindow:
  152.             newPhaseWindow.Open()
  153.  
  154.         self.curPhaseWindow=newPhaseWindow
  155.        
  156.         if self.curPhaseWindow:
  157.             self.curtain.FadeIn()
  158.         else:
  159.             app.Exit()
  160.  
  161.     def CreatePopupDialog(self):
  162.         self.popupWindow = PopupDialog()
  163.         self.popupWindow.LoadDialog()
  164.         self.popupWindow.SetCenterPosition()
  165.         self.popupWindow.Hide()
  166.  
  167.  
  168.     ## SelectPhase
  169.     ########################################################################################## 
  170.     def SetLoginPhase(self):
  171.         net.Disconnect()
  172.  
  173.         try:
  174.             import introLogin
  175.             self.SetPhaseWindow(introLogin.LoginWindow(self))
  176.         except:
  177.             import exception
  178.             exception.Abort("networkModule.SetLoginPhase")
  179.  
  180.     def SetSelectEmpirePhase(self):
  181.         try:
  182.             import introEmpire 
  183.             self.SetPhaseWindow(introEmpire.SelectEmpireWindow(self))
  184.         except:
  185.             import exception
  186.             exception.Abort("networkModule.SetSelectEmpirePhase")
  187.  
  188.  
  189.     def SetReselectEmpirePhase(self):
  190.         try:
  191.             import introEmpire
  192.             self.SetPhaseWindow(introEmpire.ReselectEmpireWindow(self))
  193.         except:
  194.             import exception
  195.             exception.Abort("networkModule.SetReselectEmpirePhase")
  196.  
  197.     def SetSelectCharacterPhase(self):
  198.         try:
  199.             localeInfo.LoadLocaleData()
  200.             import introSelect
  201.             self.popupWindow.Close()
  202.             self.SetPhaseWindow(introSelect.SelectCharacterWindow(self))
  203.         except:
  204.             import exception
  205.             exception.Abort("networkModule.SetSelectCharacterPhase")
  206.  
  207.     def SetCreateCharacterPhase(self):
  208.         try:
  209.             import introCreate
  210.             self.SetPhaseWindow(introCreate.CreateCharacterWindow(self))
  211.         except:
  212.             import exception
  213.             exception.Abort("networkModule.SetCreateCharacterPhase")
  214.  
  215. #   def SetTestGamePhase(self, x, y):
  216. #       try:
  217. #           import introLoading
  218. #           loadingPhaseWindow=introLoading.LoadingWindow(self)
  219. #           loadingPhaseWindow.LoadData(x, y)
  220. #           self.SetPhaseWindow(loadingPhaseWindow)
  221. #       except:
  222. #           import exception
  223. #           exception.Abort("networkModule.SetLoadingPhase")
  224.  
  225.  
  226.  
  227.     def SetLoadingPhase(self):
  228.         try:
  229.             import introLoading
  230.             self.SetPhaseWindow(introLoading.LoadingWindow(self))
  231.         except:
  232.             import exception
  233.             exception.Abort("networkModule.SetLoadingPhase")
  234.  
  235.     def SetGamePhase(self):
  236.         try:
  237.             import game
  238.             self.popupWindow.Close()
  239.             self.SetPhaseWindow(game.GameWindow(self))
  240.         except:
  241.             raise
  242.             import exception
  243.             exception.Abort("networkModule.SetGamePhase")
  244.  
  245.     ################################
  246.     # Functions used in python
  247.  
  248.     ## Login
  249.     # def Connect(self):       
  250.         # import constInfo
  251.         # if constInfo.KEEP_ACCOUNT_CONNETION_ENABLE:
  252.             # net.ConnectToAccountServer(self.addr, self.port, self.account_addr, self.account_port)
  253.         # else:
  254.             # net.ConnectTCP(self.addr, self.port)
  255.    
  256.     def Connect(self):
  257.         net.SetMarkServer(self.serverInfo[1][0], self.serverInfo[1][1])
  258.         app.SetGuildMarkPath(self.serverInfo[1][2])
  259.        
  260.         app.SetGuildSymbolPath(self.serverInfo[1][3])
  261.  
  262.         channelData = self.serverInfo[2][self.channelIndex]
  263.         net.ConnectToAccountServer(channelData[1], channelData[2], channelData[1], channelData[3])
  264.    
  265.     def SetServerInfo(self, serverInfo, channelIndex):
  266.         self.serverInfo = serverInfo
  267.         self.channelIndex = channelIndex
  268.  
  269.     # def SetConnectInfo(self, addr, port, account_addr=0, account_port=0):
  270.         # self.addr = addr
  271.         # self.port = port
  272.         # self.account_addr = account_addr
  273.         # self.account_port = account_port
  274.  
  275.     def GetConnectAddr(self):
  276.         return self.addr
  277.  
  278.     def SetLoginInfo(self, id, pwd):
  279.         self.id = id
  280.         self.pwd = pwd
  281.         net.SetLoginInfo(id, pwd)
  282.  
  283.     def CancelEnterGame(self):
  284.         pass
  285.  
  286.     ## Select
  287.     def SetCharacterSlot(self, slot):
  288.         self.slot=slot
  289.  
  290.     def GetCharacterSlot(self):
  291.         return self.slot
  292.  
  293.     ## Empty
  294.     def EmptyFunction(self):
  295.         pass
Add Comment
Please, Sign In to add comment