Advertisement
P3NG3R

[METIN2] ChannelChanger

Sep 23rd, 2013
2,893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 11.74 KB | None | 0 0
  1. # ChannelChanger Tool 1.1a
  2. #
  3. # The boredom is a big lord.
  4. # Idea was came from DaRealFreak@elitepvpers.com && Sanchez@GGMT2.hu
  5. #
  6. # Version info:
  7. #    v1.0  : GUI
  8. #            Connection with variables
  9. #    v1.1  : Connection with serverInfo
  10. #            Serverstatus checker and show the states
  11. #            Disabled connection if the server is FULL or Offline
  12. #            Added special map interrupter(dt,dc etc..)
  13. #    v1.1a : Added refresh button
  14. #
  15. # Used sources:
  16. #    - DaRealFreak's ChannelChangerBot
  17. #    - YMIR's client >,< introLogin.py
  18. #    - My brain C:
  19. #
  20. # Bugs:
  21. #    Sometimes the "SetLoginInfo" function is late and try to connect the client to the server
  22. #    with wrong ID/PW. In this case the "OnLoginFailure" function will run with "WRONGPWD" and
  23. #    "NOID" arguments(1x-1x) from the introLogin.py. This fault peculiar to the slower PC-s or lagg.
  24. #    And not recommended the fast channel switching.
  25. #
  26. # Do not forget to add this in your introLogin.LoginWindow.Connect
  27. #    net.ACCOUNT_ID = id
  28. #    net.ACCOUNT_PW = pwd
  29. #
  30. # Haters gonna hate. Please keep your comment in yourself & Press Alt + F13!
  31. # Enjoy, and sorry for my bad English, P3NG3R
  32. import ui
  33. import net
  34. import app
  35. import chat
  36. import math
  37. import wndMgr
  38. import serverInfo
  39. import background
  40. import ServerStateChecker
  41.  
  42. class ChannelChanger(ui.ScriptWindow):
  43.     def __init__(self):
  44.         ui.ScriptWindow.__init__(self)
  45.  
  46.         self.__Init_ChannelChanger()
  47.         self.__Load_Gui()
  48.         self.__Fill_Up_ChannelList()
  49.  
  50.     def __del__(self):
  51.         ui.ScriptWindow.__del__(self)
  52.  
  53.     def Destroy(self):
  54.         self.Hide()
  55.         return TRUE
  56.  
  57.     def __Init_ChannelChanger(self):
  58.         ServerStateChecker.Create(self)
  59.         self.SetSize(150, 175)
  60.         self.SetPosition(
  61.             (wndMgr.GetScreenWidth() / 2) - int(math.floor(self.GetWidth() / 2.)),
  62.             (wndMgr.GetScreenHeight() / 2) - int(math.floor(self.GetHeight() / 2.))
  63.         )
  64.         #self.AddFlag("movable")
  65.         self.AddFlag("float")
  66.         self.Show()
  67.  
  68.     def __Load_Gui(self):
  69.         self.Board = ui.Board()
  70.         self.Board.SetParent(self)
  71.         self.Board.SetSize(self.GetWidth(), self.GetHeight())
  72.         self.Board.SetPosition(0, 0)
  73.         #self.Board.AddFlag("movable")
  74.         self.Board.AddFlag("float")
  75.         self.Board.Show()
  76.  
  77.         self.TitleBar = ui.TitleBar()
  78.         self.TitleBar.SetParent(self.Board)
  79.         self.TitleBar.SetPosition(7, 7)
  80.         self.TitleBar.MakeTitleBar(self.GetWidth() - 2 * 7, 'bloodyblue')
  81.         self.TitleBar.SetCloseEvent(self.Close)
  82.         self.TitleBar.Show()
  83.  
  84.         self.RefreshButton = ui.Button()
  85.         self.RefreshButton.SetParent(self.TitleBar)
  86.         self.RefreshButton.SetPosition(3, 3)
  87.         self.RefreshButton.SetUpVisual("d:/ymir work/ui/game/guild/refresh_button_01.sub")
  88.         self.RefreshButton.SetOverVisual("d:/ymir work/ui/game/guild/refresh_button_02.sub")
  89.         self.RefreshButton.SetDownVisual("d:/ymir work/ui/game/guild/refresh_button_03.sub")
  90.         self.RefreshButton.SetToolTipText("Frissítés", 0, - 23)
  91.         #                                 "Refresh"
  92.         self.RefreshButton.SetEvent(lambda : self.__Fill_Up_ChannelList())
  93.         self.RefreshButton.Show()
  94.  
  95.         self.TitleText = ui.TextLine()
  96.         self.TitleText.SetParent(self.TitleBar)
  97.         self.TitleText.SetPosition(0, 4)
  98.         self.TitleText.SetText("CH - Választó")
  99.         #                      "CH - Switcher"
  100.         self.TitleText.SetWindowHorizontalAlignCenter()
  101.         self.TitleText.SetHorizontalAlignCenter()
  102.         self.TitleText.Show()
  103.  
  104.         self.ServerName = ui.TextLine()
  105.         self.ServerName.SetParent(self.TitleBar)
  106.         self.ServerName.SetPosition(0, self.TitleBar.GetHeight())
  107.         self.ServerName.SetText(str(net.GetServerInfo()).split(",")[0])
  108.         self.ServerName.SetWindowHorizontalAlignCenter()
  109.         self.ServerName.SetHorizontalAlignCenter()
  110.         self.ServerName.Show()
  111.  
  112.         self.ChannelListBase = ui.SlotBar()
  113.         self.ChannelListBase.SetParent(self.Board)
  114.         self.ChannelListBase.SetSize(self.Board.GetWidth() - 2 * 16, 5 * 18 - 4)
  115.         self.ChannelListBase.SetPosition(16 , 7 + self.TitleBar.GetHeight() + 6 + 10)
  116.         self.ChannelListBase.Show()
  117.  
  118.         self.ChannelList = ui.ListBox()
  119.         self.ChannelList.SetParent(self.ChannelListBase)
  120.         self.ChannelList.SetSize(self.ChannelListBase.GetWidth()- 20, self.ChannelListBase.GetHeight())
  121.         self.ChannelList.SetPosition(0, 0)
  122.         self.ChannelList.SetEvent(ui.__mem_func__(self.__OnSelectChannel))
  123.         self.ChannelList.Show()
  124.  
  125.         self.ChangeButton = ui.Button()
  126.         self.ChangeButton.SetParent(self.Board)
  127.         self.ChangeButton.SetPosition(self.Board.GetWidth() / 2 - 44, self.Board.GetHeight() - 35)
  128.         self.ChangeButton.SetUpVisual('d:/ymir work/ui/public/Large_button_01.sub')
  129.         self.ChangeButton.SetOverVisual('d:/ymir work/ui/public/Large_button_02.sub')
  130.         self.ChangeButton.SetDownVisual('d:/ymir work/ui/public/Large_button_03.sub')
  131.         self.ChangeButton.SetEvent(lambda : self.__OnClickConnectButton())
  132.         self.ChangeButton.SetText("Mehet")
  133.         #                         "Go"
  134.         self.ChangeButton.Show()
  135.         self.DisableChangeButton()
  136.  
  137.         self.ChannelListScrollBar = ui.ScrollBar()
  138.         self.ChannelListScrollBar.SetParent(self.ChannelListBase)
  139.         self.ChannelListScrollBar.SetPosition(18, 3)
  140.         self.ChannelListScrollBar.SetScrollBarSize(83)
  141.         self.ChannelListScrollBar.SetWindowHorizontalAlignRight()
  142.         self.ChannelListScrollBar.SetScrollEvent(ui.__mem_func__(self.__OnScrollChannelList))
  143.         self.ChannelListScrollBar.Show()
  144.  
  145.     def DisableChangeButton(self):
  146.         self.ChangeButton.Disable()
  147.         self.ChangeButton.Down()
  148.         self.ChangeButton.ButtonText.SetFontColor(0.4, 0.4, 0.4)
  149.  
  150.     def EnableChangeButton(self):
  151.         self.ChangeButton.Enable()
  152.         self.ChangeButton.SetUp()
  153.         self.ChangeButton.ButtonText.SetFontColor(1, 1, 1)
  154.  
  155.     def __GetRegionID(self):
  156.         return 0
  157.  
  158.     def __GetServerID(self):
  159.         regionID = self.__GetRegionID()
  160.         for i in serverInfo.REGION_DICT[regionID].keys():
  161.             if serverInfo.REGION_DICT[regionID][i]["name"] == net.GetServerInfo().split(",")[0]:
  162.                 serverID = int(i)
  163.                 break
  164.  
  165.         return serverID
  166.  
  167.     def __Fill_Up_ChannelList(self):
  168.         self.__RequestServerStateList()
  169.         self.__RefreshServerStateList()
  170.         #self.ChannelList.SelectItem(0)
  171.  
  172.     def __RequestServerStateList(self):
  173.         regionID = self.__GetRegionID()
  174.         serverID = self.__GetServerID()
  175.  
  176.         try:
  177.             channelDict = serverInfo.REGION_DICT[regionID][serverID]["channel"]
  178.         except:
  179.             return
  180.  
  181.         for id, channelDataDict in channelDict.items():
  182.             key=channelDataDict["key"]
  183.             ip=channelDataDict["ip"]
  184.             udp_port=channelDataDict["udp_port"]
  185.             ServerStateChecker.Request(key, ip, udp_port)
  186.  
  187.     def __RefreshServerStateList(self):
  188.         regionID = self.__GetRegionID()
  189.         serverID = self.__GetServerID()
  190.         bakChannelID = self.ChannelList.GetSelectedItem()
  191.  
  192.         self.ChannelList.ClearItem()
  193.  
  194.         try:
  195.             channelDict = serverInfo.REGION_DICT[regionID][serverID]["channel"]
  196.         except:
  197.             return
  198.  
  199.         for channelID, channelDataDict in channelDict.items():
  200.             channelName = channelDataDict["name"]
  201.             channelState = channelDataDict["state"]
  202.             self.ChannelList.InsertItem(channelID, "%s %s" % (channelName, channelState))
  203.  
  204.         self.ChannelList.SelectItem(bakChannelID-1)
  205.  
  206.     def NotifyChannelState(self, addrKey, state):
  207.         try:
  208.             stateName = serverInfo.STATE_DICT[state]
  209.         except:
  210.             stateName = serverInfo.STATE_NONE
  211.  
  212.         regionID  = int(addrKey / 1000)
  213.         serverID  = int(addrKey / 10) % 100
  214.         channelID = addrKey % 10
  215.  
  216.         try:
  217.             serverInfo.REGION_DICT[regionID][serverID]["channel"][channelID]["state"] = stateName
  218.             self.__RefreshChannelStateList()
  219.         except:
  220.             pass
  221.  
  222.     def __IsSpecialMap(self):
  223.         dis_maps = [
  224.             "season1/metin2_map_oxevent",
  225.             "season2/metin2_map_guild_inside01",
  226.             "season2/metin2_map_empirewar01",
  227.             "season2/metin2_map_empirewar02",
  228.             "season2/metin2_map_empirewar03",
  229.             "metin2_map_dragon_timeattack_01",
  230.             "metin2_map_dragon_timeattack_02",
  231.             "metin2_map_dragon_timeattack_03",
  232.             "metin2_map_skipia_dungeon_boss",
  233.             "metin2_map_skipia_dungeon_boss2",
  234.             "metin2_map_devilsCatacomb",
  235.             "metin2_map_deviltower1",
  236.             "metin2_map_t1",
  237.             "metin2_map_t2",
  238.             "metin2_map_t3",
  239.             "metin2_map_t4",
  240.             "metin2_map_t5",
  241.             "metin2_map_wedding_01",
  242.             "metin2_map_duel"
  243.         ]
  244.         if str(background.GetCurrentMapName()) in dis_maps:
  245.             return TRUE
  246.         return FALSE
  247.  
  248.     def __OnSelectChannel(self):
  249.         if self.ChangeButton.IsDown():
  250.             self.EnableChangeButton()
  251.  
  252.         ##< Works but not need >##
  253.         #regionID = self.__GetRegionID()
  254.         #serverID = self.__GetServerID()
  255.         #channelID = self.ChannelList.GetSelectedItem()
  256.         #if self.__IsSpecialMap():
  257.         #   self.DisableChangeButton()
  258.         #   return
  259.         #elif serverInfo.REGION_DICT[regionID][serverID]["channel"][channelID]["state"] == serverInfo.STATE_NONE:
  260.         #   self.DisableChangeButton()
  261.         #   return
  262.  
  263.     def __OnScrollChannelList(self):
  264.         viewItemCount = self.ChannelList.GetViewItemCount()
  265.         itemCount = self.ChannelList.GetItemCount()
  266.         pos = self.ChannelListScrollBar.GetPos() * (itemCount - viewItemCount)
  267.         self.ChannelList.SetBasePos(int(pos))
  268.  
  269.     def __OnClickConnectButton(self):
  270.         regionID = self.__GetRegionID()
  271.         serverID = self.__GetServerID()
  272.         channelID = self.ChannelList.GetSelectedItem()
  273.         if not channelID:
  274.             chat.AppendChat(1, "Nem választotál ki csatornát!")
  275.             #                  "You did not select a channel!"
  276.             return
  277.  
  278.         try:
  279.             serverName = serverInfo.REGION_DICT[regionID][serverID]["name"]
  280.             channelName = serverInfo.REGION_DICT[regionID][serverID]["channel"][channelID]["name"]
  281.             addrKey = serverInfo.REGION_DICT[regionID][serverID]["channel"][channelID]["key"]
  282.             ip = serverInfo.REGION_DICT[regionID][serverID]["channel"][channelID]["ip"]
  283.             tcp_port = serverInfo.REGION_DICT[regionID][serverID]["channel"][channelID]["tcp_port"]
  284.             state = serverInfo.REGION_DICT[regionID][serverID]["channel"][channelID]["state"]
  285.  
  286.             account_ip = serverInfo.REGION_AUTH_SERVER_DICT[regionID][serverID]["ip"]
  287.             account_port = serverInfo.REGION_AUTH_SERVER_DICT[regionID][serverID]["port"]
  288.  
  289.             markKey = regionID * 1000 + serverID * 10
  290.             markAddrValue=serverInfo.MARKADDR_DICT[markKey]
  291.             net.SetMarkServer(markAddrValue["ip"], markAddrValue["tcp_port"])
  292.             app.SetGuildMarkPath(markAddrValue["mark"])
  293.             app.SetGuildSymbolPath(markAddrValue["symbol_path"])
  294.         except:
  295.             chat.AppendChat(1, "Hiba történt a csatlakozás közben!")
  296.             #                  "An error occurred while connect!"
  297.             return
  298.  
  299.         if state == serverInfo.STATE_NONE:
  300.             chat.AppendChat(1, "Sajnálom a kiválasztott csatorna nem elérhető!")
  301.             #                  "Sorry the selected channel is offline!"
  302.             return
  303.         elif state == serverInfo.STATE_DICT[3]:
  304.             chat.AppendChat(1, "Sajnálom a kiválasztott csatorna telítve van!")
  305.             #                  "Sorry the selected channel is full!"
  306.             return
  307.         elif net.GetServerInfo().strip().split(", ")[1] == self.ChannelList.textDict[self.ChannelList.selectedLine].strip().split(" ")[0]:
  308.             chat.AppendChat(1, "Te jelenleg is a kiválasztott csatornán tartózkodsz!")
  309.             #                  "You are already on the selected channel!"
  310.             return
  311.         elif self.__IsSpecialMap():
  312.             chat.AppendChat(1, "Sajnálom ezen a területen nem válthatsz csatornát kilépés nélkül!")
  313.             #                  "Sorry in this area you cannot change channel without logout!"
  314.             return
  315.  
  316.         self.Close()
  317.         net.SetServerInfo("%s, %s" % (serverName, channelName))
  318.         self.DirectConnect(ip, tcp_port, account_ip, account_port)
  319.  
  320.     def DirectConnect(self, ChannelIP, ChannelPort, AuthServerIP, AuthServerPort):
  321.         #net.SetLoginInfo("xPengii", "kiU2_w1A_q2olDle9")
  322.         net.SetLoginInfo(decode_string(net.ACCOUNT_ID), decode_string(net.ACCOUNT_PW))
  323.         net.ConnectToAccountServer(ChannelIP, ChannelPort, AuthServerIP, AuthServerPort)
  324.         net.DirectEnter(0)
  325.         net.SendSelectCharacterPacket(0)
  326.         net.SendEnterGamePacket()
  327.  
  328.     def Show(self):
  329.         ui.ScriptWindow.Show(self)
  330.  
  331.     def Close(self):
  332.         ServerStateChecker.Destroy(self)
  333.         self.Hide()
  334.         return TRUE
  335.  
  336.     def OnPressEscapeKey(self):
  337.         self.Close()
  338.         return TRUE
  339.  
  340.     def OnUpdate(self):
  341.         ServerStateChecker.Update()
  342.  
  343. iom = ChannelChanger()
  344. iom.Show()
  345. chat.AppendChat(1, "#DEV#{Succesfully loaded}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement