Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void amatchmaker::preparejoin(const fstring host)
- {
- gengine->addonscreendebugmessage(-1, 5.f, fcolor::cyan, "preparejoin");
- ionlinesubsystem* onlinesub = online::getsubsystem(getworld());
- if (onlinesub)
- {
- if (gengine->createnamednetdriver(getworld(), name_gamenetdriver, name_gamenetdriver))
- {
- gengine->addonscreendebugmessage(-1, 5.f, fcolor::green, "success creating netdriver");
- gengine->addonscreendebugmessage(-1, 5.f, fcolor::emerald, fstring("port from new netdriver: ").append(fstring::fromint(getportfromnetdriver(onlinesub->getinstancename()))));
- unetdriver* netdriver = getworld() ? gengine->findnamednetdriver(getworld(), name_gamenetdriver) : null;
- if (netdriver)
- {
- uipnetdriver* ipnetdriver = cast<uipnetdriver>(netdriver);
- if (ipnetdriver)
- {
- fstring error;
- //ipnetdriver->initlisten(getworld(), localurl, false, error);
- ipnetdriver->initconnect(getworld(), furl(), error);
- gengine->addonscreendebugmessage(-1, 5.f, fcolor::red, error);
- socket = ipnetdriver->socket;
- if (socket)
- {
- //tsharedptr<finternetaddr> outaddr;
- //socket->getaddress(outaddr);
- gengine->addonscreendebugmessage(-1, 5.f, fcolor::cyan, fstring("port from new socket: ").append(fstring::fromint(socket->getportno())));
- ftimespan threadwaittime = ftimespan::frommilliseconds(100);
- udpreceiver = new fudpsocketreceiver(socket, threadwaittime, text("udp receiver"));
- udpreceiver->ondatareceived().binduobject(this, &amatchmakeractor::recv);
- udpreceiver->start();
- fstring remoteurl = fstring("stun.l.google.com");
- faddressinforesult addrinforesult = isocketsubsystem::get(platform_socketsubsystem)->getaddressinfo(*remoteurl, nullptr, eaddressinfoflags::default, esocketprotocolfamily::none, esockettype::socktype_unknown);
- faddressinforesultdata* dnsresult = addrinforesult.results.getdata();
- if (dnsresult == nullptr)
- {
- gengine->addonscreendebugmessage(-1, 5.f, fcolor::red, "no dns result");
- return;
- }
- uint32 ip;
- dnsresult->address->getip(ip);
- gengine->addonscreendebugmessage(-1, 5.f, fcolor::cyan, fstring("dns: ").append(dnsresult->address->tostring(false)));
- int32 remoteport = 19302;
- tsharedptr<finternetaddr> remoteaddr = isocketsubsystem::get(platform_socketsubsystem)->createinternetaddr();
- remoteaddr->setip(ip);
- remoteaddr->setport(remoteport);
- int32 bytessent = 0;
- fstring data = "what do you want";
- farraywriter writer;
- writer << data;
- uint8* bytebuffer = new uint8();
- int32 bytescopied = hextobytes("000100002112a4423b2430270358b8e359f073e5", bytebuffer);
- socket->sendto(writer.getdata(), writer.num(), bytessent, *remoteaddr);
- //socket->sendto(bytebuffer, bytescopied, bytessent, *remoteaddr);
- gengine->addonscreendebugmessage(-1, 5.f, fcolor::green, fstring::fromint(bytessent));
- }
- else
- {
- gengine->addonscreendebugmessage(-1, 5.f, fcolor::red, "failed creating socket");
- }
- }
- }
- }
- else
- {
- gengine->addonscreendebugmessage(-1, 5.f, fcolor::red, "failed creating netdriver");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment