-- "myKey" must be added to micromacro/lib/net.lua local updateTime = 2000; local serverIP = "127.0.0.1"; local GUID_offset = 0x20 local listen = nil; -- ************************ SERVER SIDE ************************************************************ function partyServer() local count = 1; local listening = FALSE; repeat repeat printf("Trying to open connection. Try number: %d\n",count); listen = netOpenCon("0.0.0.0", "myKey"); yrest(1000); count = count+1; until listen~=nil if listen then printf("Trying to make connection listening\n") if( netListen(listen) ~= 0 ) then printf("Error making connection listen.\n"); else listening = TRUE; printf("Connection listening.\n"); end end until TRUE == listening registerTimer("partyLeader", updateTime, partyLeader); printf("partyLeader timer started\n"); return; end function partyLeader() -- printf("\n Partyleader here\n"); -- Lets wait until a client joins our server. local client = netPollListen(listen); -- Give it some tries while client == nil do --and 10 > count do -- printf("Looking for clients\n") client = netPollListen(listen); yrest(50); end if client~= nil then -- printf("We have client: %s\n",client); -- Lets send the other side a text message. -- We will use the ID of 12 (we just make this up) to mean that -- we want to send a GUID message. player:update(); if player.TargetPtr~=0 then local GUID = getTargetGUID(player.TargetPtr); if GUID~=0 then -- printf("Sending message\n") if( netSendMessage(client, 12, GUID) ~= 0 ) then print("You have been disconnected."); end end end end end -- ************************ GENERAL FUNCTIONS ************************************************************ function getTargetGUID(_target) local GUID_offset = 0x20 GUID = memoryReadInt( getProc(), _target+GUID_offset); GUID = GUID or 0 return GUID end function findEnemyByGUID(_GUID) local obj = nil; local objGUID; local objectList = CObjectList(); objectList:update(); for i = 0,objectList:size() do obj = objectList:getObject(i); if obj ~= nil then --printf("_GUID: %d\n",_GUID) objGUID = getTargetGUID(obj.Address) --printf("objGUID: %d\n",objGUID) if _GUID == objGUID then return obj.Address end end end return nil; end -- ************************ CLIENT SIDE ************************************************************ function getGUIDfromServer() local GUID = nil; local status; local server = netOpenCon("myKey"); local count = 0; -- printf("\n Partymember here\n"); if( netConnect(server, serverIP) ~= 0 ) then printf("Error initializing connection."); end -- We wait until our connection status is either an error, or a successful connection status = netConnectStatus(server); -- Give it another try while status == 0 do -- printf("Status check\n") yrest(100); status = netConnectStatus(server); end if status > 0 then -- printf("Connection success!\n"); while GUID == nil do -- printf("Waiting for server message\n"); while( netPollMessages(server) ) do -- printf("We have a message\n"); local message = netGetMessage(server); local messId = message[1]; if( messId == 12 ) then -- It looks like they sent us a GUID message. local messText = message[2]; -- printf("Received message: %d\n", messText); GUID = messText; end yrest(100); end yrest(100); count = count + 1; if count > 5 then -- it takes too long netCloseCon(server); return nil; end end netCloseCon(server); return GUID; else printf("Connection failed!\n"); end yrest(100); return nil; end