maket socket
This commit is contained in:
@@ -24,6 +24,7 @@ struct TCommand
|
||||
* write(const char *buffer, size_t size)
|
||||
*/
|
||||
|
||||
|
||||
template <class CSocket>
|
||||
void sendCommand(CSocket &socket, const TCommand &command)
|
||||
{
|
||||
@@ -31,3 +32,5 @@ void sendCommand(CSocket &socket, const TCommand &command)
|
||||
}
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,18 @@
|
||||
|
||||
#include "commands.h"
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include<iostream>
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <iphlpapi.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#pragma comment(lib, "Ws2_32.lib")
|
||||
|
||||
#pragma pack(push,1)
|
||||
|
||||
/* Для всех команд:
|
||||
@@ -20,10 +32,10 @@
|
||||
* 3 - подсветка белым цветом
|
||||
*/
|
||||
|
||||
// Команда, предотвращающая переход в автоматический режим
|
||||
// Команда, предотвращающая переход в автоматический режим
|
||||
|
||||
#define CMD_NOP 0x00
|
||||
struct CMD_NOP_T: public TCommand
|
||||
struct CMD_NOP_T : public TCommand
|
||||
{
|
||||
};
|
||||
|
||||
@@ -44,13 +56,13 @@ struct CMD_NOP_T: public TCommand
|
||||
#define OPT_COLOR_COUNT 3
|
||||
|
||||
#define CMD_GET_COLOR 0x01
|
||||
struct CMD_GET_COLOR_T: public TCommand
|
||||
struct CMD_GET_COLOR_T : public TCommand
|
||||
{
|
||||
byte code;
|
||||
};
|
||||
|
||||
#define CMD_SET_COLOR 0x02
|
||||
struct CMD_SET_COLOR_T: public TCommand
|
||||
struct CMD_SET_COLOR_T : public TCommand
|
||||
{
|
||||
byte code;
|
||||
byte r, g, b;
|
||||
@@ -59,7 +71,7 @@ struct CMD_SET_COLOR_T: public TCommand
|
||||
// Команда включения/выключения подсветки всего здания
|
||||
|
||||
#define CMD_SET_BUILDING_STATE 0x03
|
||||
struct CMD_SET_BUILDING_STATE_T: public TCommand
|
||||
struct CMD_SET_BUILDING_STATE_T : public TCommand
|
||||
{
|
||||
byte building;
|
||||
byte state;
|
||||
@@ -68,7 +80,7 @@ struct CMD_SET_BUILDING_STATE_T: public TCommand
|
||||
// Команда включения/выключения подсветки отдельной квартиры
|
||||
|
||||
#define CMD_SET_ROOM_STATE 0x04
|
||||
struct CMD_SET_ROOM_STATE_T: public TCommand
|
||||
struct CMD_SET_ROOM_STATE_T : public TCommand
|
||||
{
|
||||
byte building;
|
||||
byte strip;
|
||||
@@ -79,7 +91,7 @@ struct CMD_SET_ROOM_STATE_T: public TCommand
|
||||
// Команда включения/выключения подсветки всего этажа
|
||||
|
||||
#define CMD_SET_FLOOR_STATE 0x05
|
||||
struct CMD_SET_FLOOR_STATE_T: public TCommand
|
||||
struct CMD_SET_FLOOR_STATE_T : public TCommand
|
||||
{
|
||||
byte building;
|
||||
byte floor;
|
||||
@@ -89,7 +101,7 @@ struct CMD_SET_FLOOR_STATE_T: public TCommand
|
||||
// Команда установки подсветки всех квартир
|
||||
|
||||
#define CMD_SET_ALL_STATE 0x06
|
||||
struct CMD_SET_ALL_STATE_T: public TCommand
|
||||
struct CMD_SET_ALL_STATE_T : public TCommand
|
||||
{
|
||||
byte state;
|
||||
};
|
||||
@@ -98,7 +110,7 @@ struct CMD_SET_ALL_STATE_T: public TCommand
|
||||
// millisec - время в миллисекундах
|
||||
|
||||
#define CMD_SET_DOME_TIME 0x07
|
||||
struct CMD_SET_DOME_TIME_T: public TCommand
|
||||
struct CMD_SET_DOME_TIME_T : public TCommand
|
||||
{
|
||||
word millisec;
|
||||
};
|
||||
@@ -112,18 +124,53 @@ struct CMD_SET_DOME_TIME_T: public TCommand
|
||||
#define PART_OFFICE_LIGHT 0x08
|
||||
|
||||
#define CMD_SET_PART_MODE 0x08
|
||||
struct CMD_SET_PART_MODE_T: public TCommand
|
||||
struct CMD_SET_PART_MODE_T : public TCommand
|
||||
{
|
||||
byte mode;
|
||||
byte part;
|
||||
};
|
||||
|
||||
/* Пример отправки команды:
|
||||
*
|
||||
* DECLARE_CMD(CMD_SET_BUILDING_STATE, cmd);
|
||||
* cmd.building = 1;
|
||||
* cmd.state = 1;
|
||||
* sendCommand(socket, cmd);
|
||||
*/
|
||||
//Пример отправки команды:
|
||||
/*DECLARE_CMD(CMD_SET_BUILDING_STATE, cmd);
|
||||
cmd.building = 1;
|
||||
cmd.state = 1;
|
||||
sendCommand(socket, cmd);*/
|
||||
|
||||
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
class CSocket {
|
||||
char* ipAddr_;
|
||||
u_short port_;
|
||||
|
||||
public:
|
||||
CSocket(char* ipAddr, u_short port) {
|
||||
ipAddr_ = ipAddr;
|
||||
port_ = port;
|
||||
}
|
||||
void write(const char* buffer, size_t size) {
|
||||
int clientSocket = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (clientSocket == -1) {
|
||||
std::cerr << "Error creating socket" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
struct sockaddr_in serverAddress;
|
||||
serverAddress.sin_family = AF_INET;
|
||||
serverAddress.sin_port = htons(port_); // Порт сервера
|
||||
serverAddress.sin_addr.s_addr = inet_addr(ipAddr_); // IP адрес сервера
|
||||
|
||||
if (connect(clientSocket, (struct sockaddr*)&serverAddress, sizeof(serverAddress)) == -1) {
|
||||
std::cerr << "Error connecting to server" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (send(clientSocket, buffer, size, 0) == -1) {
|
||||
std::cerr << "Error sending message" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
closesocket(clientSocket);
|
||||
}
|
||||
};
|
||||
@@ -4,10 +4,12 @@
|
||||
#include "cppGI.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Misc/paths.h"
|
||||
#include "commands_model.h"
|
||||
#include "Engine/levelstreamingdynamic.h"
|
||||
|
||||
/*for working tarray::Contains*/
|
||||
CSocket* soc;
|
||||
|
||||
/*for working tarray::Contains*/
|
||||
bool operator==(const Fcppcoords& c1, const Fcppcoords& c2) {
|
||||
return c1.flat == c2.flat &&
|
||||
c1.floor == c2.floor &&
|
||||
@@ -94,6 +96,7 @@ void UcppGI::cppLvlManage(UObject* WorldContextObject, Fcppcoords currentCoords,
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void UcppGI::cppCoordsEq(Fcppcoords coords, Fcppcoords coords1, bool relevantMinus2, bool fastEq, bool& flat_, bool& type_, bool& zone_, bool& house_, bool& section_, bool& floor_, bool& fullEq)
|
||||
{
|
||||
bool* outLvl[6] = { &flat_, &type_, &zone_, &house_, §ion_, &floor_ };
|
||||
@@ -118,3 +121,74 @@ void UcppGI::cppCoordsEq(Fcppcoords coords, Fcppcoords coords1, bool relevantMin
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void UcppGI::avoidAutoState()
|
||||
{
|
||||
if (!soc)return;
|
||||
|
||||
DECLARE_CMD(CMD_NOP, cmd);
|
||||
sendCommand(*soc, cmd);
|
||||
}
|
||||
|
||||
void UcppGI::makeSocket(FString ip, int port)
|
||||
{
|
||||
char* ipc=NULL;
|
||||
wcstombs(ipc, *ip, ip.Len());
|
||||
soc = new CSocket(ipc, port);
|
||||
}
|
||||
|
||||
void UcppGI::setColor(uint8 code, FColor color)
|
||||
{
|
||||
if (!soc)return;
|
||||
|
||||
DECLARE_CMD(CMD_SET_COLOR, cmd);
|
||||
cmd.code = code;
|
||||
cmd.r = color.R, cmd.g=color.G, cmd.b=color.B;
|
||||
sendCommand(*soc, cmd);
|
||||
|
||||
}
|
||||
|
||||
void UcppGI::setLight(int house, int floor, int strip, uint8 state)
|
||||
{
|
||||
if (!soc)return;
|
||||
|
||||
if (strip < 0) {
|
||||
if (floor < 0) {
|
||||
if (house < 0) {
|
||||
DECLARE_CMD(CMD_SET_ALL_STATE, cmd);
|
||||
cmd.state = state;
|
||||
sendCommand(*soc, cmd);
|
||||
return;
|
||||
}
|
||||
DECLARE_CMD(CMD_SET_BUILDING_STATE, cmd);
|
||||
cmd.state = state;
|
||||
cmd.building = house;
|
||||
sendCommand(*soc, cmd);
|
||||
return;
|
||||
}
|
||||
DECLARE_CMD(CMD_SET_FLOOR_STATE, cmd);
|
||||
cmd.state = state;
|
||||
cmd.building = house;
|
||||
cmd.floor = floor;
|
||||
sendCommand(*soc, cmd);
|
||||
return;
|
||||
}
|
||||
DECLARE_CMD(CMD_SET_ROOM_STATE, cmd);
|
||||
cmd.state = state;
|
||||
cmd.building = house;
|
||||
cmd.floor = floor;
|
||||
cmd.strip = strip;
|
||||
sendCommand(*soc, cmd);
|
||||
|
||||
}
|
||||
|
||||
void UcppGI::setPartState(uint8 part, uint8 state)
|
||||
{
|
||||
if (!soc)return;
|
||||
DECLARE_CMD(CMD_SET_PART_MODE, cmd);
|
||||
cmd.mode = state;
|
||||
cmd.part = part;
|
||||
sendCommand(*soc, cmd);
|
||||
|
||||
|
||||
}
|
||||
|
||||
+58
-23
@@ -7,7 +7,7 @@
|
||||
#include "cppGI.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
@@ -15,18 +15,18 @@ struct Fcppcoords
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, category = "default")
|
||||
int32 flat = -1;
|
||||
UPROPERTY(BlueprintReadWrite, category = "default")
|
||||
int32 type = 0;
|
||||
int32 flat = -1;
|
||||
UPROPERTY(BlueprintReadWrite, category = "default")
|
||||
int32 zone = 1;
|
||||
int32 type = 0;
|
||||
UPROPERTY(BlueprintReadWrite, category = "default")
|
||||
int32 house = -1;
|
||||
int32 zone = 1;
|
||||
UPROPERTY(BlueprintReadWrite, category = "default")
|
||||
int32 section = -1;
|
||||
int32 house = -1;
|
||||
UPROPERTY(BlueprintReadWrite, category = "default")
|
||||
int32 floor = -1;
|
||||
int32 section = -1;
|
||||
UPROPERTY(BlueprintReadWrite, category = "default")
|
||||
int32 floor = -1;
|
||||
};
|
||||
|
||||
|
||||
@@ -35,16 +35,16 @@ struct FcppLevelStruct
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
Fcppcoords coords;
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
bool dontUnload = false;
|
||||
Fcppcoords coords;
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
FString path;
|
||||
bool dontUnload = false;
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
float Z = 0;
|
||||
FString path;
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
int32 anotherLvl = -1;
|
||||
float Z = 0;
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
int32 anotherLvl = -1;
|
||||
};
|
||||
|
||||
UCLASS()
|
||||
@@ -52,20 +52,55 @@ class MASHAROVDEV_API UcppGI : public UGameInstance
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
UFUNCTION(blueprintcallable, category = "cppFuncLib")
|
||||
static void cppCoordsEq(Fcppcoords coords, Fcppcoords coords1, bool relevantMinus2, bool fastEq, bool& flat_, bool& type_, bool& zone_, bool& house_, bool& section_, bool& floor_, bool& fullEq);
|
||||
UFUNCTION(blueprintcallable, category = "cppFuncLib")
|
||||
static void cppCoordsEq(Fcppcoords coords, Fcppcoords coords1, bool relevantMinus2, bool fastEq, bool& flat_, bool& type_, bool& zone_, bool& house_, bool& section_, bool& floor_, bool& fullEq);
|
||||
|
||||
|
||||
/*returns array of levels for binding and array of lvlstruct for loading*/
|
||||
|
||||
/*returns array of levels for binding and array of lvlstruct for loading*/
|
||||
UFUNCTION(blueprintcallable, Category = "Level Loading", meta = (WorldContext = "WorldContextObject"))
|
||||
void cppLvlManage(UObject* WorldContextObject, Fcppcoords currentCoords, uint8 currentState, TArray<ULevelStreaming*>& Levelss);
|
||||
|
||||
void cppLvlManage(UObject* WorldContextObject, Fcppcoords currentCoords, uint8 currentState, TArray<ULevelStreaming*>& Levelss);
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "levelLoading", meta = (MultiLine = "true"))
|
||||
TArray<FcppLevelStruct> cpplevelLIst;
|
||||
TArray<FcppLevelStruct> cpplevelLIst;
|
||||
/** used if need to load some levels instantly. -2 of any coord is use current. */
|
||||
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "Level Loading", meta = (MultiLine = "true"))
|
||||
TArray<Fcppcoords> cpplvlsForLoading;
|
||||
TArray<Fcppcoords> cpplvlsForLoading;
|
||||
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "Level Loading", meta = (MultiLine = "true"))
|
||||
TArray<FName> cppdynamicLvls;
|
||||
TArray<FName> cppdynamicLvls;
|
||||
|
||||
UFUNCTION(blueprintcallable, Category = "maketConnection")
|
||||
void avoidAutoState();
|
||||
UFUNCTION(blueprintcallable, Category = "maketConnection")
|
||||
void makeSocket(FString ip, int port);
|
||||
/*codes:
|
||||
*0 - öâåò êóïîëà â ðåæèìå ðàáîòû ñ ïðèëîæåíèåì
|
||||
*1 - ïåðâûé öâåò ïîäñâåòêè êâàðòèð (íàïðèìåð, ïîäñâåòêà âñåãî çäàíèÿ ïðè åãî âûáîðå)
|
||||
*2 - âòîðîé öâåò ïîäñâåòêè êâàðòèð (íàïðèìåð, ïîäñâåòêà âûáðàííûõ êâàðòèð) */
|
||||
UFUNCTION(blueprintcallable, Category = "maketConnection")
|
||||
void setColor(uint8 code, FColor color);
|
||||
/*assign -1 to set all, i.e. flat==-1 -> set whole floor, floor==-1 -> set whole house
|
||||
states:
|
||||
*0 — Âûêëþ÷èòü ïîäñâåòêó(íåëüçÿ èçìåíèòü)
|
||||
*1 — Ïîäñâåòêà ïåðâûì öâåòîì(çàäà¸òñÿ êîìàíäîé)
|
||||
*2 — Ïîäñâåòêà âòîðûì öâåòîì(çàäà¸òñÿ êîìàíäîé)
|
||||
*3 — Ïîäñâåòêà áåëûì öâåòîì(íåëüçÿ èçìåíèòü)*/
|
||||
UFUNCTION(blueprintcallable, Category = "maketConnection")
|
||||
void setLight(int house=-1, int floor=-1, int strip=-1, uint8 state=0);
|
||||
/*assign -1 to set all, i.e. flat==-1 -> set whole floor, floor==-1 -> set whole house
|
||||
* parts:
|
||||
*Âñå ÷àñòè — 255
|
||||
*Êóïîë — 0
|
||||
*Âñå çäàíèÿ — 2
|
||||
*Óëè÷íàÿ ïîäñâåòêà — 4
|
||||
*Îôèñíàÿ ïîäñâåòêà — 8
|
||||
*
|
||||
states:
|
||||
*0 — Âûêëþ÷èòü ÷àñòü
|
||||
*1 — Âêëþ÷èòü ÷àñòü, â ðó÷íîì ðåæèìå(÷àñòü ðàáîòàåò â ñòàòè÷åñêîì ðåæèìå, äåíü íî÷ü íà íåé, íå ìåíÿåòñÿ)
|
||||
*2 — Âêëþ÷èòü ÷àñòü, â àâòîìàòè÷åñêîì ðåæèìå(÷àñòü ðàáîòàåò â ðåæèìå ñìåíû äíÿ è íî÷è)*/
|
||||
UFUNCTION(blueprintcallable, Category = "maketConnection")
|
||||
|
||||
void setPartState(uint8 part, uint8 state);
|
||||
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user