Advertisement
zlofenix

ZLO BF3 Launcher API

Feb 20th, 2014
2,430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.23 KB | None | 0 0
  1. /*
  2. 6.0.0
  3. ZLO_RunClient changed
  4. New events 36, 37
  5. 3 new listeners: ZMessage, Version, Stat
  6. New functions: GetVersion, GetStats
  7. */
  8. using System;
  9. using System.Runtime.CompilerServices;
  10. using System.Runtime.InteropServices;
  11.  
  12.  
  13. namespace zloTest
  14. {
  15.     class LauncherTest
  16.     {
  17.         int lastserver;
  18.         public LauncherTest()
  19.         {
  20.             ZLO_Init();
  21.             SetupEvents();
  22.             if (!ZLO_ListenGOS())
  23.                 Console.WriteLine("Cannot open GOS port for listen, its ok if you runned 2 different launchers, for client and for server for example");
  24.         }
  25.  
  26.         public void StartServer()
  27.         {
  28.             if (!ZLO_ListenServer())
  29.             {
  30.                 Console.WriteLine("Cannot open Server port for listen, its fatal");
  31.                 return;
  32.             }
  33.             if (ZLO_ConnectMServer("emu.bf3.zloemu.org"))
  34.                 Console.WriteLine("Connected to server master server");
  35.             else
  36.             {
  37.                 Console.WriteLine("Cannot connect to server master server, its fatal");
  38.                 return;
  39.             }
  40.         }
  41.  
  42.         public void StartClient()
  43.         {
  44.             if (ZLO_ConnectMClient("emu.bf3.zloemu.org"))
  45.             {
  46.                 Console.WriteLine("Connected to client master server");
  47.                 ZLO_AuthClient("mail@mail.mail","pass");//from zloemu.org
  48.             }
  49.             else
  50.             {
  51.                 Console.WriteLine("Cannot connect to client master server, its fatal");
  52.                 return;
  53.             }
  54.         }
  55.  
  56.         ~LauncherTest()
  57.         {
  58.             ZLO_Close();
  59.         }
  60.  
  61.         private void EventListener(int zevent)
  62.         {
  63.             Console.WriteLine("Event {0}", zevent);
  64.             if (zevent == 0)
  65.             {
  66. //.net 4.5 fix
  67.                 string name = Marshal.PtrToStringAnsi(ZLO_GetName());
  68. //
  69.                 Console.WriteLine("MemberID {0} name {1}", ZLO_GetID(), name);
  70.                 ZLO_GetVersion(1);//your launcher id
  71.                 ZLO_GetServerList();
  72. //DO NOT ASK STATS(ZLO_GetStats) HERE, its big packet, and with serverlist = connection can die
  73.             }
  74.             else if (zevent == 3)
  75.             {
  76.                 Console.WriteLine("Server select ok");
  77.                 int t = ZLO_RunClient(1);//0 - single, 1 - multi
  78.                 if (t != 0)
  79.                     Console.WriteLine("Run client error {0}", t);
  80.             }
  81.             else if (zevent == 24)
  82.                 ZLO_SelectServer(lastserver);
  83.             else if (zevent == 36)
  84.                 Console.WriteLine("Stats begin");
  85.             else if (zevent == 37)
  86.                 Console.WriteLine("Stats end");
  87.         }
  88.  
  89.         private void ClientListener(string type, string value)
  90.         {
  91.             Console.WriteLine("Client: [{0}] {1}", type, value);
  92.         }
  93.  
  94.         private void ServerListener(int id, bool added)
  95.         {
  96.             if (added) lastserver = id;
  97. /*
  98.             if (added)
  99.                 Console.WriteLine("server {0} added", id);
  100.             else
  101.                 Console.WriteLine("server {0} removed", id);
  102. */
  103.         }
  104.  
  105.         private void ServerListenerName(int id, string name)
  106.         {
  107. //          Console.WriteLine("server {0} name = {1}", id, name);
  108.         }
  109.  
  110.         private void ServerListenerAttr(int id, string name, string value)
  111.         {
  112. //          Console.WriteLine("server {0} attr {1} = {2}", id, name, value);
  113.         }
  114.  
  115.         private void ServerListenerCap(int id, int cap0, int cap1)
  116.         {
  117. //          Console.WriteLine("server {0} cap0 = {1} cap1 = {2}", id, cap0, cap1);
  118.         }
  119.  
  120.         private void ServerListenerState(int id, int state)
  121.         {
  122. //          Console.WriteLine("server {0} state = {1}", id, state);
  123.         }
  124.  
  125.         private void ServerListenerPlayers(int id, int players)
  126.         {
  127. //          Console.WriteLine("server {0} players = {1}", id, players);
  128.         }
  129.  
  130.         private void ServerListenerAddr(int id, string ip, int port)
  131.         {
  132. //          Console.WriteLine("server {0} ip = {1} port = {2}", id, ip, port);
  133.         }
  134.  
  135.         private void ZMessageListener(string msg)
  136.         {
  137.             Console.WriteLine("ZMessage {0}", msg);
  138.         }
  139.  
  140.         private void VersionListener(int version)
  141.         {
  142.             Console.WriteLine("Launcher version from server {0}", version);
  143.         }
  144.  
  145.         private void StatListener(string name, float value)
  146.         {
  147.             Console.WriteLine("name {0} value {1}", name, value);
  148.         }
  149.  
  150.         public void SetupEvents()
  151.         {
  152.             EventListenerInstance = new tEventListener(EventListener);
  153.             ClientListenerInstance = new tClientListener(ClientListener);
  154.             ServerListenerInstance = new tServerListener(ServerListener);
  155.             ServerListenerNameInstance = new tServerListenerName(ServerListenerName);
  156.             ServerListenerAttrInstance = new tServerListenerAttr(ServerListenerAttr);
  157.             ServerListenerCapInstance = new tServerListenerCap(ServerListenerCap);
  158.             ServerListenerStateInstance = new tServerListenerState(ServerListenerState);
  159.             ServerListenerPlayersInstance = new tServerListenerPlayers(ServerListenerPlayers);
  160.             ServerListenerAddrInstance = new tServerListenerAddr(ServerListenerAddr);
  161.             ZMessageListenerInstance = new tZMessageListener(ZMessageListener);
  162.             VersionListenerInstance = new tVersionListener(VersionListener);
  163.             StatListenerInstance = new tStatListener(StatListener);
  164.  
  165.             ZLO_SetEventListener(EventListenerInstance);
  166.             ZLO_SetClientListener(ClientListenerInstance);
  167.             ZLO_SetServerListener(ServerListenerInstance);
  168.             ZLO_SetServerListenerName(ServerListenerNameInstance);
  169.             ZLO_SetServerListenerAttr(ServerListenerAttrInstance);
  170.             ZLO_SetServerListenerCap(ServerListenerCapInstance);
  171.             ZLO_SetServerListenerState(ServerListenerStateInstance);
  172.             ZLO_SetServerListenerPlayers(ServerListenerPlayersInstance);
  173.             ZLO_SetServerListenerAddr(ServerListenerAddrInstance);
  174.             ZLO_SetZMessageListener(ZMessageListenerInstance);
  175.             ZLO_SetVersionListener(VersionListenerInstance);
  176.             ZLO_SetStatListener(StatListenerInstance);
  177.         }
  178.  
  179.         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  180.         private delegate void tEventListener(int zevent);
  181.         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  182.         private delegate void tClientListener(string type, string value);
  183.         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  184.         private delegate void tServerListener(int id, bool added);
  185.         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  186.         private delegate void tServerListenerName(int id, string name);
  187.         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  188.         private delegate void tServerListenerAttr(int id, string name, string value);
  189.         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  190.         private delegate void tServerListenerCap(int id, int cap0, int cap1);
  191.         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  192.         private delegate void tServerListenerState(int id, int state);
  193.         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  194.         private delegate void tServerListenerPlayers(int id, int players);
  195.         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  196.         private delegate void tServerListenerAddr(int id, string ip, int port);
  197.         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  198.         private delegate void tZMessageListener(string msg);
  199.         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  200.         private delegate void tVersionListener(int version);
  201.         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  202.         private delegate void tStatListener(string name, float value);
  203.  
  204.         private tEventListener EventListenerInstance;
  205.         private tClientListener ClientListenerInstance;
  206.         private tServerListener ServerListenerInstance;
  207.         private tServerListenerName ServerListenerNameInstance;
  208.         private tServerListenerAttr ServerListenerAttrInstance;
  209.         private tServerListenerCap ServerListenerCapInstance;
  210.         private tServerListenerState ServerListenerStateInstance;
  211.         private tServerListenerPlayers ServerListenerPlayersInstance;
  212.         private tServerListenerAddr ServerListenerAddrInstance;
  213.         private tZMessageListener ZMessageListenerInstance;
  214.         private tVersionListener VersionListenerInstance;
  215.         private tStatListener StatListenerInstance;
  216.  
  217.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  218.         public static extern void ZLO_Init();
  219.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  220.         public static extern bool ZLO_ListenGOS();
  221.     //Events
  222.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  223.         private static extern void ZLO_SetEventListener(tEventListener l);
  224.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  225.         private static extern void ZLO_SetClientListener(tClientListener l);
  226.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  227.         private static extern void ZLO_SetServerListener(tServerListener l);
  228.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  229.         private static extern void ZLO_SetServerListenerName(tServerListenerName l);
  230.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  231.         private static extern void ZLO_SetServerListenerAttr(tServerListenerAttr l);
  232.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  233.         private static extern void ZLO_SetServerListenerCap(tServerListenerCap l);
  234.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  235.         private static extern void ZLO_SetServerListenerState(tServerListenerState l);
  236.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  237.         private static extern void ZLO_SetServerListenerPlayers(tServerListenerPlayers l);
  238.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  239.         private static extern void ZLO_SetServerListenerAddr(tServerListenerAddr l);
  240.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  241.         private static extern void ZLO_SetZMessageListener(tZMessageListener l);
  242.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  243.         private static extern void ZLO_SetVersionListener(tVersionListener l);
  244.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  245.         private static extern void ZLO_SetStatListener(tStatListener l);
  246.     //Client
  247.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  248.         public static extern bool ZLO_ConnectMClient(string addr);
  249.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  250.         public static extern void ZLO_AuthClient(string login, string pass);
  251.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  252.         public static extern void ZLO_GetServerList();
  253.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  254.         public static extern void ZLO_SelectServer(int id);
  255.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  256.         public static extern int ZLO_RunClient(int mode);
  257.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  258.         public static extern int ZLO_GetID();
  259. //.net 4.5 fix
  260.         [DllImport("Launcher.dll", CallingConvention=CallingConvention.Cdecl)]
  261.         public static extern IntPtr ZLO_GetName();
  262. //
  263.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  264.         public static extern void ZLO_GetVersion(int launcher);
  265.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  266.         public static extern void ZLO_GetStats();
  267.  
  268.     //Server
  269.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  270.         public static extern bool ZLO_ListenServer();
  271.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  272.         public static extern bool ZLO_ConnectMServer(string addr);
  273.     //
  274.         [DllImport("Launcher.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
  275.         public static extern void ZLO_Close();
  276.     }
  277. }
  278.  
  279. public class Test
  280. {
  281.     public static void Main()
  282.     {
  283.         zloTest.LauncherTest dll = new zloTest.LauncherTest();
  284. //      dll.StartServer();
  285.         dll.StartClient();
  286.         Console.WriteLine("Press enter to exit");
  287.         Console.ReadLine();
  288.         dll = null;
  289.     }
  290. }
  291.  
  292. /*
  293. Events:
  294. //
  295. //Client events
  296. //
  297. 0 - Auth success
  298. 1 - Auth error
  299. 2 - Old LaucherDLL
  300. //
  301. 3 - Server select ok
  302. 4 - server select not found - error 1
  303. 5 - server select full - error 2
  304. 6 - server select not ready - error 3
  305. //
  306. 23 - server list begin
  307. 24 - server list end
  308. 27 - launcher(client) disconnected from master
  309. 28 - mclient timeouted and disconnected
  310. //
  311. 36 - stats begin
  312. 37 - stats end
  313. //
  314. //Server events
  315. //
  316. 29 - Server connected
  317. 30 - Server auth success
  318. 31 - Server auth fail
  319. 32 - launcher(server) disconnected from master
  320. 33 - mserver timeouted and disconnected
  321. 34 - launcher(server) connected to master
  322. 35 - Server disconnected
  323. //
  324. 666 - BANNED
  325. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement