Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2020
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <WS2tcpip.h>
  3. #include <string>
  4. #include "Engine/World.h"
  5. #include "Containers/UnrealString.h"
  6.  
  7. #pragma comment (lib, "ws2_32.lib")
  8.  
  9. #include "SendPlayerInfo.h"
  10.  
  11. SOCKET out;
  12. sockaddr_in server;
  13.  
  14. USendPlayerInfo::USendPlayerInfo()
  15. {
  16. PrimaryComponentTick.bCanEverTick = true;
  17.  
  18. }
  19.  
  20. void USendPlayerInfo::BeginPlay()
  21. {
  22. Super::BeginPlay();
  23. StartSocket();
  24.  
  25. }
  26.  
  27. void USendPlayerInfo::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
  28. {
  29. Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
  30. FVector MyCharacter = GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation();
  31. FString CharVector = MyCharacter.ToString();
  32. std::string VectorString(TCHAR_TO_UTF8(*CharVector));
  33. const char* message = VectorString.c_str();
  34. WriteToSocket(message);
  35.  
  36. }
  37.  
  38. void USendPlayerInfo::StartSocket()
  39. {
  40. WSADATA data;
  41. WORD version = MAKEWORD(2, 2);
  42. int wSOk = WSAStartup(version, &data);
  43. if (wSOk != 0) {
  44. fprintf(stderr, "WSAStartup failed.\n");
  45. exit(1);
  46. }
  47. server.sin_family = AF_INET;
  48. server.sin_port = htons(54100);
  49.  
  50. inet_pton(AF_INET, "192.168.1.172", &server.sin_addr);
  51. out = socket(AF_INET, SOCK_DGRAM, 0);
  52. }
  53.  
  54. void USendPlayerInfo::WriteToSocket(const char* message)
  55. {
  56. int sendOK = sendto(out, message, sizeof(message), 0, (sockaddr*)&server, sizeof(server));
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement