From b3d4b10fc1b31ef99dadaa29a93de877c6940885 Mon Sep 17 00:00:00 2001 From: Jousey Date: Thu, 29 Sep 2022 16:56:49 -0400 Subject: [PATCH 01/15] Typo --- ServerSubnautica/Clients/HandleClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ServerSubnautica/Clients/HandleClient.cs b/ServerSubnautica/Clients/HandleClient.cs index 102a60e..591b6b4 100644 --- a/ServerSubnautica/Clients/HandleClient.cs +++ b/ServerSubnautica/Clients/HandleClient.cs @@ -127,7 +127,7 @@ public void loop() public void endConnection() { lock (Server._lock) Server.list_clients.Remove(id); - Console.WriteLine("Someone deconnected, id: " + id); + Console.WriteLine("Someone disconnected, id: " + id); client.Client.Shutdown(SocketShutdown.Both); client.Close(); clientAction.redirectCall(new string[] { id.ToString() }, NetworkCMD.getIdCMD("Disconnected")); From 47fffe4b4a9f5f1f232ae671b6dc8d5a54a55020 Mon Sep 17 00:00:00 2001 From: Jousey Date: Thu, 29 Sep 2022 23:36:25 -0400 Subject: [PATCH 02/15] New files --- ClientSubnautica/ClientSubnautica.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ClientSubnautica/ClientSubnautica.csproj b/ClientSubnautica/ClientSubnautica.csproj index a5d2647..664a88c 100644 --- a/ClientSubnautica/ClientSubnautica.csproj +++ b/ClientSubnautica/ClientSubnautica.csproj @@ -34,6 +34,7 @@ + @@ -44,6 +45,7 @@ + From 0045edadabf1832d74f9867de860fa43b0e321e3 Mon Sep 17 00:00:00 2001 From: Jousey Date: Thu, 29 Sep 2022 23:36:53 -0400 Subject: [PATCH 03/15] Added function for SaveGame --- ServerSubnautica/SendData/FunctionManager.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ServerSubnautica/SendData/FunctionManager.cs b/ServerSubnautica/SendData/FunctionManager.cs index 658cf97..4b6b8d5 100644 --- a/ServerSubnautica/SendData/FunctionManager.cs +++ b/ServerSubnautica/SendData/FunctionManager.cs @@ -40,5 +40,11 @@ public void Disconnected(string[] param) client.broadcast(NetworkCMD.getIdCMD("Disconnected") + ":" + param[0]+"/END/", int.Parse(param[0])); } + public void SaveGameRequest(string[] param) + { + //client.broadcast(NetworkCMD.getIdCMD("SaveGameRequest") + ":" + param[0] + ":" + param[1] + ";" + param[2] + ";" + param[3] + ";" + param[4] + ";" + param[5] + ";" + param[6]+"/END/", int.Parse(param[0])); + Console.WriteLine("SavingGame, player position: " + ":" + param[0] + ":" + param[1] + ";" + param[2] + ";" + param[3] + ";" + param[4] + ";" + param[5] + ";" + param[6]); + } + } } From 8a5300be461897881287cd2c0d2f40fb0107ee89 Mon Sep 17 00:00:00 2001 From: Jousey Date: Thu, 29 Sep 2022 23:37:14 -0400 Subject: [PATCH 04/15] Added updated Dictionary --- ClientSubnautica/MultiplayerManager/NetworkCMD.cs | 3 ++- ServerSubnautica/NetworkCMD.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ClientSubnautica/MultiplayerManager/NetworkCMD.cs b/ClientSubnautica/MultiplayerManager/NetworkCMD.cs index 10cea1c..b81cf7e 100644 --- a/ClientSubnautica/MultiplayerManager/NetworkCMD.cs +++ b/ClientSubnautica/MultiplayerManager/NetworkCMD.cs @@ -17,7 +17,8 @@ class NetworkCMD {"5", "AllId"}, {"6", "GetTimePassed"}, {"7", "PickupItem"}, - {"8", "SpawnBasePiece"} + {"8", "SpawnBasePiece"}, + {"9", "SaveGameRequest"} }; public static string Translate(string idCMD) diff --git a/ServerSubnautica/NetworkCMD.cs b/ServerSubnautica/NetworkCMD.cs index a732962..a983239 100644 --- a/ServerSubnautica/NetworkCMD.cs +++ b/ServerSubnautica/NetworkCMD.cs @@ -17,7 +17,8 @@ class NetworkCMD {"5", "AllId"}, {"6", "GetTimePassed"}, {"7", "PickupItem"}, - {"8", "SpawnBasePiece"} + {"8", "SpawnBasePiece"}, + {"9", "SaveGameRequest"} }; public static string Translate(string idCMD) From eacc12830b92152fb340f4cc9d4d70e56d547655 Mon Sep 17 00:00:00 2001 From: Jousey Date: Thu, 29 Sep 2022 23:37:46 -0400 Subject: [PATCH 05/15] Files for sending data to server and patching the save button in pause menu --- .../ClientManager/Patches/OnSaveGame.cs | 38 ++++++++++ .../SendData/SendOnSaveGame.cs | 69 +++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 ClientSubnautica/ClientManager/Patches/OnSaveGame.cs create mode 100644 ClientSubnautica/MultiplayerManager/SendData/SendOnSaveGame.cs diff --git a/ClientSubnautica/ClientManager/Patches/OnSaveGame.cs b/ClientSubnautica/ClientManager/Patches/OnSaveGame.cs new file mode 100644 index 0000000..7f231d8 --- /dev/null +++ b/ClientSubnautica/ClientManager/Patches/OnSaveGame.cs @@ -0,0 +1,38 @@ +using System.Net.Sockets; +using System.Threading; +using ClientSubnautica.MultiplayerManager.SendData; +using HarmonyLib; +using UnityEngine; +using UnityEngine.UI; +using UWE; + +namespace ClientSubnautica.ClientManager.Patches +{ + class SaveGame + { + [HarmonyPatch(typeof(IngameMenu), "SaveGame")] + public class Patches + { + [HarmonyPostfix] + static bool Prefix(IngameMenu __instance) + { + + GameObject mainPanel = __instance.mainPanel; + Button save = __instance.saveButton; + + save.onClick.AddListener(SaveButtonClick); + + mainPanel.SetActive(true); + + return false; + } + private static void SaveButtonClick() + { + Player player = Player.main; + Vector3 position = player.transform.position; + + SendOnSaveGame.SendPosition(position); + } + } + } +} \ No newline at end of file diff --git a/ClientSubnautica/MultiplayerManager/SendData/SendOnSaveGame.cs b/ClientSubnautica/MultiplayerManager/SendData/SendOnSaveGame.cs new file mode 100644 index 0000000..d7816b4 --- /dev/null +++ b/ClientSubnautica/MultiplayerManager/SendData/SendOnSaveGame.cs @@ -0,0 +1,69 @@ +using System; +using System.Net.Sockets; +using System.Text; +using System.Threading; +using ClientSubnautica.MultiplayerManager.ReceiveData; +using UnityEngine; + +namespace ClientSubnautica.MultiplayerManager.SendData +{ + public class SendOnSaveGame + { + public static void SendPosition(Vector3 position) + { + NetworkStream ns2 = InitializeConnection.client.GetStream(); + try + { + string x = ""; + string y = ""; + string z = ""; + string rotx = ""; + string roty = ""; + string rotz = ""; + string rotw = ""; + string rotxTemp = ""; + string rotyTemp = ""; + string rotzTemp = ""; + string rotwTemp = ""; + while (true) + { + try + { + Quaternion roTemp = MainCameraControl.main.viewModel.transform.rotation; + rotxTemp = roTemp.x.ToString(); + rotyTemp = roTemp.y.ToString(); + rotzTemp = roTemp.z.ToString(); + rotwTemp = roTemp.w.ToString(); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + if (position.x.ToString() != x | + position.y.ToString() != y | + position.z.ToString() != z | + rotxTemp != rotx | rotyTemp != roty | + rotzTemp != rotz | rotwTemp != rotw) + { + byte[] msgresponse = Encoding.ASCII.GetBytes(""); + Array.Clear(msgresponse, 0, msgresponse.Length); + + msgresponse = Encoding.ASCII.GetBytes(NetworkCMD.getIdCMD("SaveGameReq") + ":" + + position.x + ";" + + position.y + ";" + + position.z + ";" + rotx + ";" + + roty + ";" + rotz + ";" + rotw + "/END/"); + + ns2.Write(msgresponse, 0, msgresponse.Length); + } + } + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + } +} \ No newline at end of file From e0f5fb26a49e33393dbc25de0add5d48ae01507d Mon Sep 17 00:00:00 2001 From: Jousey Date: Thu, 29 Sep 2022 23:47:25 -0400 Subject: [PATCH 06/15] removed unused menuconfig --- ClientSubnautica/ClientSubnautica.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/ClientSubnautica/ClientSubnautica.csproj b/ClientSubnautica/ClientSubnautica.csproj index 664a88c..9c31af8 100644 --- a/ClientSubnautica/ClientSubnautica.csproj +++ b/ClientSubnautica/ClientSubnautica.csproj @@ -54,7 +54,6 @@ - From 28f86dc5029d07393008840fc4407e8f77da17ba Mon Sep 17 00:00:00 2001 From: Jousey Date: Fri, 30 Sep 2022 13:41:54 -0400 Subject: [PATCH 07/15] Changed game save console message --- ServerSubnautica/SendData/FunctionManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ServerSubnautica/SendData/FunctionManager.cs b/ServerSubnautica/SendData/FunctionManager.cs index 4b6b8d5..79e779c 100644 --- a/ServerSubnautica/SendData/FunctionManager.cs +++ b/ServerSubnautica/SendData/FunctionManager.cs @@ -42,8 +42,8 @@ public void Disconnected(string[] param) public void SaveGameRequest(string[] param) { - //client.broadcast(NetworkCMD.getIdCMD("SaveGameRequest") + ":" + param[0] + ":" + param[1] + ";" + param[2] + ";" + param[3] + ";" + param[4] + ";" + param[5] + ";" + param[6]+"/END/", int.Parse(param[0])); - Console.WriteLine("SavingGame, player position: " + ":" + param[0] + ":" + param[1] + ";" + param[2] + ";" + param[3] + ";" + param[4] + ";" + param[5] + ";" + param[6]); + //client.broadcast(NetworkCMD.getIdCMD("SaveGameRequest") + ":" + param[0] + ":" + param[1] + ":" + param[2] + ":" + param[3] + ":" + param[4] + ":" + param[5] + ":" + param[6]+"/END/", int.Parse(param[0])); + Console.WriteLine("id: " + param[0] + " saving at position: " + param[1] + ";" + param[2] + ";" + param[3] + ";" + param[4] + ";" + param[5] + ";" + param[6] + ";" + param[7]); } } From 8dcea8c0153e4273493f4103e8995c143dfc8df3 Mon Sep 17 00:00:00 2001 From: Jousey Date: Fri, 30 Sep 2022 13:51:53 -0400 Subject: [PATCH 08/15] Unnecessary "e" variable for exceptions --- ClientSubnautica/ClientManager/Patches/AddMenuButton.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ClientSubnautica/ClientManager/Patches/AddMenuButton.cs b/ClientSubnautica/ClientManager/Patches/AddMenuButton.cs index e55e4f1..f3f7691 100644 --- a/ClientSubnautica/ClientManager/Patches/AddMenuButton.cs +++ b/ClientSubnautica/ClientManager/Patches/AddMenuButton.cs @@ -51,27 +51,27 @@ static void Postfix(string target, MainMenuRightSide __instance) GameObject.Find("Menu canvas/Panel/MainMenu/RightSide/MultiplayerMenu/SubscriptionSuccess").SetActive(true); } - catch (SocketException e) + catch (SocketException) { GameObject.Find("Menu canvas/Panel/MainMenu/RightSide/MultiplayerMenu/SubscriptionInProgress").SetActive(false); GameObject.Find("Menu canvas/Panel/MainMenu/RightSide/MultiplayerMenu/SubscriptionError").SetActive(true); } - catch (FormatException e) + catch (FormatException) { GameObject.Find("Menu canvas/Panel/MainMenu/RightSide/MultiplayerMenu/SubscriptionInProgress").SetActive(false); GameObject.Find("Menu canvas/Panel/MainMenu/RightSide/MultiplayerMenu/SubscriptionError/Text").GetComponent().text = "Invalid address ip"; GameObject.Find("Menu canvas/Panel/MainMenu/RightSide/MultiplayerMenu/SubscriptionError").SetActive(true); } - catch (IndexOutOfRangeException e) + catch (IndexOutOfRangeException) { GameObject.Find("Menu canvas/Panel/MainMenu/RightSide/MultiplayerMenu/SubscriptionInProgress").SetActive(false); GameObject.Find("Menu canvas/Panel/MainMenu/RightSide/MultiplayerMenu/SubscriptionError/Text").GetComponent().text = "No port specified or wrong ip address format"; GameObject.Find("Menu canvas/Panel/MainMenu/RightSide/MultiplayerMenu/SubscriptionError").SetActive(true); } - catch (Exception e) + catch (Exception) { GameObject.Find("Menu canvas/Panel/MainMenu/RightSide/MultiplayerMenu/SubscriptionInProgress").SetActive(false); From 7f9b27436b846c8e7a93f549da401ee1a072c501 Mon Sep 17 00:00:00 2001 From: Jousey Date: Fri, 30 Sep 2022 13:52:45 -0400 Subject: [PATCH 09/15] Changed the Save process. Now works on the 2nd click. --- .../SendData/SendOnSaveGame.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/ClientSubnautica/MultiplayerManager/SendData/SendOnSaveGame.cs b/ClientSubnautica/MultiplayerManager/SendData/SendOnSaveGame.cs index d7816b4..e2fc6e0 100644 --- a/ClientSubnautica/MultiplayerManager/SendData/SendOnSaveGame.cs +++ b/ClientSubnautica/MultiplayerManager/SendData/SendOnSaveGame.cs @@ -1,7 +1,6 @@ using System; using System.Net.Sockets; using System.Text; -using System.Threading; using ClientSubnautica.MultiplayerManager.ReceiveData; using UnityEngine; @@ -10,6 +9,11 @@ namespace ClientSubnautica.MultiplayerManager.SendData public class SendOnSaveGame { public static void SendPosition(Vector3 position) + { + bool saved = SendData(position); + } + + private static bool SendData(Vector3 position) { NetworkStream ns2 = InitializeConnection.client.GetStream(); try @@ -42,27 +46,32 @@ public static void SendPosition(Vector3 position) } if (position.x.ToString() != x | position.y.ToString() != y | - position.z.ToString() != z | + position.z.ToString() != z | rotxTemp != rotx | rotyTemp != roty | rotzTemp != rotz | rotwTemp != rotw) { + rotx = rotxTemp; + roty = rotyTemp; + rotz = rotzTemp; + rotw = rotwTemp; byte[] msgresponse = Encoding.ASCII.GetBytes(""); Array.Clear(msgresponse, 0, msgresponse.Length); - msgresponse = Encoding.ASCII.GetBytes(NetworkCMD.getIdCMD("SaveGameReq") + ":" + + msgresponse = Encoding.ASCII.GetBytes(NetworkCMD.getIdCMD("SaveGameRequest") + ":" + position.x + ";" + position.y + ";" + position.z + ";" + rotx + ";" + roty + ";" + rotz + ";" + rotw + "/END/"); ns2.Write(msgresponse, 0, msgresponse.Length); + return true; } } } catch (Exception e) { Console.WriteLine(e); - throw; + return false; } } } From 027e5910ece5e15f30f85b6c87026fac9ca77fe1 Mon Sep 17 00:00:00 2001 From: Onfimarist <55112974+Onfimarist@users.noreply.github.com> Date: Fri, 30 Sep 2022 13:53:57 -0400 Subject: [PATCH 10/15] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index d2a918b..7dc23bc 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,6 @@ Please do not forget to modify these before using: -ip address to host the server in config.json file --fix dependencies path - Please install .NET Framework 4.7.2 and set it for the ClientSubnautica project. From 77ce120a973864c50982f8e231516f4f7f06d6d5 Mon Sep 17 00:00:00 2001 From: Jousey Date: Fri, 30 Sep 2022 16:11:43 -0400 Subject: [PATCH 11/15] SQLite functions --- ServerSubnautica/Database/DAO.cs | 92 ++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 ServerSubnautica/Database/DAO.cs diff --git a/ServerSubnautica/Database/DAO.cs b/ServerSubnautica/Database/DAO.cs new file mode 100644 index 0000000..45c1ec4 --- /dev/null +++ b/ServerSubnautica/Database/DAO.cs @@ -0,0 +1,92 @@ +using System; +using System.Data.SQLite; +using System.IO; + + +namespace ServerSubnautica.Database +{ + internal class Dao + { + private static SQLiteConnection connection; + + public static SQLiteConnection CreateConnection() + { + // Create a new database connection: + connection = new SQLiteConnection("Data Source=database.db; Version = 3; New = True; Compress = True;"); + // Open the connection: + try + { + connection.Open(); + + if (!File.Exists("database.db")) + { + Console.WriteLine("Creating database"); + File.Create("database.db"); + CreateTable(connection); + } + } + catch (Exception ex) + { + Console.WriteLine(ex); + throw; + } + return connection; + } + + public static void SaveLocation(string playerId, string lastLocX, string lastLocY, string lastLocZ) + { + SQLiteCommand command = connection.CreateCommand(); + + command.CommandText = + $"INSERT INTO Players (PlayerId, LastPositionX, LastPositionY, LastPositionZ) VALUES ({playerId}, {lastLocX}, {lastLocY}, {lastLocZ})"; + command.ExecuteNonQuery(); + } + + public static string GetLocation() + { + SQLiteCommand command = connection.CreateCommand(); + command.CommandText = "SELECT * FROM Players"; + + SQLiteDataReader reader = command.ExecuteReader(); + + while (reader.Read()) + { + int readerId = reader.GetInt16(0); + float readerX = reader.GetFloat(1); + float readerY = reader.GetFloat(2); + float readerZ = reader.GetFloat(3); + + return $"{readerId};{readerX};{readerY};{readerZ}"; + } + + return null; + } + + private static void CreateTable(SQLiteConnection conn) + { + SQLiteCommand sqliteCmd = conn.CreateCommand(); + string createSql = "CREATE TABLE Players (PlayerId INT, LastPositionX REAL, LastPositionY REAL, LastPositionZ REAL)"; + string createSql1 = "CREATE TABLE Inventory (PlayerId INT, ItemId INT, Quantity INT, Misc VARCHAR(20))"; + sqliteCmd.CommandText = createSql; + sqliteCmd.ExecuteNonQuery(); + sqliteCmd.CommandText = createSql1; + sqliteCmd.ExecuteNonQuery(); + } + + public static void ReadData(SQLiteConnection conn) + { + + SQLiteCommand sqLiteCmd = conn.CreateCommand(); + sqLiteCmd.CommandText = "SELECT * FROM SampleTable WHERE 1"; + + SQLiteDataReader sqLiteDataReader = sqLiteCmd.ExecuteReader(); + + while (sqLiteDataReader.Read()) + { + string myReader = sqLiteDataReader.GetString(0); + Console.WriteLine(myReader); + } + conn.Close(); + } + } +} \ No newline at end of file From 47639cd275796a2d2d5431d262e9f2879c33774c Mon Sep 17 00:00:00 2001 From: Jousey Date: Fri, 30 Sep 2022 16:11:54 -0400 Subject: [PATCH 12/15] Saves location when player saves --- ServerSubnautica/SendData/FunctionManager.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ServerSubnautica/SendData/FunctionManager.cs b/ServerSubnautica/SendData/FunctionManager.cs index 79e779c..22ac3a7 100644 --- a/ServerSubnautica/SendData/FunctionManager.cs +++ b/ServerSubnautica/SendData/FunctionManager.cs @@ -1,5 +1,6 @@ using ClientSubnautica.MultiplayerManager.ReceiveData; using System; +using ServerSubnautica.Database; namespace ServerSubnautica { @@ -43,6 +44,7 @@ public void Disconnected(string[] param) public void SaveGameRequest(string[] param) { //client.broadcast(NetworkCMD.getIdCMD("SaveGameRequest") + ":" + param[0] + ":" + param[1] + ":" + param[2] + ":" + param[3] + ":" + param[4] + ":" + param[5] + ":" + param[6]+"/END/", int.Parse(param[0])); + Dao.SaveLocation(param[0], param[1], param[2], param[3]); Console.WriteLine("id: " + param[0] + " saving at position: " + param[1] + ";" + param[2] + ";" + param[3] + ";" + param[4] + ";" + param[5] + ";" + param[6] + ";" + param[7]); } From f988bdc6a3d93417cf55c814e97c6a664f53231a Mon Sep 17 00:00:00 2001 From: Jousey Date: Fri, 30 Sep 2022 16:12:21 -0400 Subject: [PATCH 13/15] Load database on startup --- ServerSubnautica/Server.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ServerSubnautica/Server.cs b/ServerSubnautica/Server.cs index 7a8c824..3bb9a0a 100644 --- a/ServerSubnautica/Server.cs +++ b/ServerSubnautica/Server.cs @@ -7,6 +7,7 @@ using System.Net; using System.Net.Sockets; using System.Threading; +using ServerSubnautica.Database; class Server { @@ -24,7 +25,8 @@ static void Main(string[] args) { Server server = new Server(); configParams = server.loadParam(configPath); - + + Dao.CreateConnection(); mapName = configParams["MapFolderName"].ToString(); gameInfoPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, mapName, "gameinfo.json"); From c7a9ce99d9579e7ba2510a9b10af698faf498e7d Mon Sep 17 00:00:00 2001 From: Jousey Date: Fri, 30 Sep 2022 16:12:41 -0400 Subject: [PATCH 14/15] Add SQLite to packages. --- ServerSubnautica/ServerSubnautica.csproj | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ServerSubnautica/ServerSubnautica.csproj b/ServerSubnautica/ServerSubnautica.csproj index b4da29f..28ffb40 100644 --- a/ServerSubnautica/ServerSubnautica.csproj +++ b/ServerSubnautica/ServerSubnautica.csproj @@ -9,6 +9,11 @@ + + + + + From d49828b45b24aac24f57beb0e95b4cfac051f042 Mon Sep 17 00:00:00 2001 From: Jousey <55112974+Onfimarist@users.noreply.github.com> Date: Tue, 11 Oct 2022 13:01:58 -0400 Subject: [PATCH 15/15] Removed "while (true)" loop --- .../SendData/SendOnSaveGame.cs | 67 +++++++++---------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/ClientSubnautica/MultiplayerManager/SendData/SendOnSaveGame.cs b/ClientSubnautica/MultiplayerManager/SendData/SendOnSaveGame.cs index e2fc6e0..d78c3e6 100644 --- a/ClientSubnautica/MultiplayerManager/SendData/SendOnSaveGame.cs +++ b/ClientSubnautica/MultiplayerManager/SendData/SendOnSaveGame.cs @@ -29,43 +29,40 @@ private static bool SendData(Vector3 position) string rotyTemp = ""; string rotzTemp = ""; string rotwTemp = ""; - while (true) + try { - try - { - Quaternion roTemp = MainCameraControl.main.viewModel.transform.rotation; - rotxTemp = roTemp.x.ToString(); - rotyTemp = roTemp.y.ToString(); - rotzTemp = roTemp.z.ToString(); - rotwTemp = roTemp.w.ToString(); - } - catch (Exception e) - { - Console.WriteLine(e); - throw; - } - if (position.x.ToString() != x | - position.y.ToString() != y | - position.z.ToString() != z | - rotxTemp != rotx | rotyTemp != roty | - rotzTemp != rotz | rotwTemp != rotw) - { - rotx = rotxTemp; - roty = rotyTemp; - rotz = rotzTemp; - rotw = rotwTemp; - byte[] msgresponse = Encoding.ASCII.GetBytes(""); - Array.Clear(msgresponse, 0, msgresponse.Length); + Quaternion roTemp = MainCameraControl.main.viewModel.transform.rotation; + rotxTemp = roTemp.x.ToString(); + rotyTemp = roTemp.y.ToString(); + rotzTemp = roTemp.z.ToString(); + rotwTemp = roTemp.w.ToString(); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } - msgresponse = Encoding.ASCII.GetBytes(NetworkCMD.getIdCMD("SaveGameRequest") + ":" + - position.x + ";" + - position.y + ";" + - position.z + ";" + rotx + ";" + - roty + ";" + rotz + ";" + rotw + "/END/"); + if (position.x.ToString() != x | + position.y.ToString() != y | + position.z.ToString() != z | + rotxTemp != rotx | rotyTemp != roty | + rotzTemp != rotz | rotwTemp != rotw) + { + rotx = rotxTemp; + roty = rotyTemp; + rotz = rotzTemp; + rotw = rotwTemp; + byte[] msgresponse = Encoding.ASCII.GetBytes(""); + Array.Clear(msgresponse, 0, msgresponse.Length); + msgresponse = Encoding.ASCII.GetBytes(NetworkCMD.getIdCMD("SaveGameRequest") + ":" + + position.x + ";" + + position.y + ";" + + position.z + ";" + rotx + ";" + + roty + ";" + rotz + ";" + rotw + "/END/"); - ns2.Write(msgresponse, 0, msgresponse.Length); - return true; - } + ns2.Write(msgresponse, 0, msgresponse.Length); + return true; } } catch (Exception e) @@ -73,6 +70,8 @@ private static bool SendData(Vector3 position) Console.WriteLine(e); return false; } + + return false; } } } \ No newline at end of file