public static void UploadHive(Hive hive) { string temp = string.Format("{8}/uploadhives?t={9}&branch_id={0}&date_sent={1}&location={2}&hive_body={3}&honey_super={4}&frames={5}&hive_species={6}&forage_environment={7}", hive.BranchId, hive.Date.ToString("yyyy-MM-dd"), hive.Location, hive.HiveBody, hive.HoneySuper, hive.Frames, hive.Species, hive.ForageEnv, DbControllerUrl, token); //System.IO.File.Create(@"C:\Database\" + temp + ".txt"); ServerCommunication.UploadDataGet(temp); }
public static bool IsLoginCorrect(string email, string password) { string tmp = ServerCommunication.DownloadDataGet(string.Format("{0}/finduser?t={3}&email={1}&password={2}", GuiControllerUrl, email, password, token)); tmp = tmp.Substring(1, tmp.Length - 2); return(bool.Parse(tmp)); }
/// <summary> /// Add a new user to the Users table /// </summary> /// <param name="Name">Full name of user</param> /// <param name="Address">Number and Street name</param> /// <param name="Postcode">User's postcode</param> /// <param name="Email">Email address</param> /// <param name="Phone">Contact phone number</param> /// <param name="Username">Username</param> /// <param name="Password">Password</param> /// <returns></returns> public static string AddUser(string Name, string Address, string Postcode, string Email, string Phone, string Username, string Password, int PermissionLevel) { if (!ServerCommunication.IsActive) { return("Connection not set"); //Ensure server communication is active } if (clientPermissionLevel < 2) { return(null); } //First encrypt user's new password string salt = SecurityManager.GenerateNewSALT(); string encPass = SecurityManager.OneWayEncryptor(Password, salt); string permission = SecurityManager.GetPermissionString(PermissionLevel); //Get permission string //Then compile into list string List <string> columns = new List <string>() { "Name", "Address", "Postcode", "Email", "Phone", "Username", "Password", "LastLogin", "Salt", "Permisison" }; List <string> newData = new List <string>() { Name, Address, Postcode, Email, Phone, Username, encPass, DateTime.Today.Date.ToString(), salt, permission }; //Place all data ready for encryption //Now Encrypt data in list List <string> encryptedData = SecurityManager.EncryptDatabaseData(columns, newData); //Encrypt all data return(ServerCommunication.NewTableEntry("Users", encryptedData)); //Add data to table }
public string FetchPublicKeyOfContact(String phoneNumber) { // Get the public key of the contact through a server call Registry taskRegistry = ServerCommunication.GetRegistry(phoneNumber); return(taskRegistry.PublicKey); }
private void OpenStartupProject() { #if DEBUG #else ServerCommunication.LoadWebFile("web-project.evox"); #endif }
// Use this for initialization void Start () { player = GameObject.FindObjectOfType<Player>(); otherPlayers = new Dictionary<uint, OtherPlayer>(); server = GetComponent<ServerCommunication>(); server.onGameInfoReceived += (id, others) => { foreach (KeyValuePair<uint, ServerCommunication.Player> pair in others) { var other = pair.Value; AddPlayer(pair.Value); } server.EnterGame(server.player.id.ToString(), player.gameObject.transform.position, player.hitPoints); isConnected = true; }; server.onPlayerMoved += other => { otherPlayers[other.id].gameObject.transform.position = other.pos; }; server.onPlayerConnected += AddPlayer; server.onPlayerDisconnected += other => { Destroy(otherPlayers[other.id].gameObject); }; server.onPlayerUpdateHealth += (other, health) => { if (other.id == server.player.id) player.hitPoints = health; else otherPlayers[other.id].health = health; }; server.onPlayerUpdateState += (other, state) => { if (other.id != server.player.id) otherPlayers[other.id].state = state; }; }
/// <summary> /// Listen any ServerCommunication from the connection to the server /// </summary> public void Listener() { try { while (!terminate) { ConsoleManager.TrackWriteLine(ConsoleColor.White, "[" + Thread.CurrentThread.Name + "] Wainting Communication...\n"); ServerCommunication communication = Net.RecieveServerCommunication(this._comm.GetStream()); //On gère la ressource et on continue d'écouter HandlingServerCommunication(communication); } } catch (System.IO.IOException e) { ConsoleManager.TrackWriteLine(ConsoleColor.DarkRed, "[" + Thread.CurrentThread.Name + "] The connection to the server has ended !"); ConsoleManager.TrackWriteLine(ConsoleColor.DarkRed, e.Message); KillClient(); } catch (System.Runtime.Serialization.SerializationException e) { ConsoleManager.TrackWriteLine(ConsoleColor.DarkRed, "[" + Thread.CurrentThread.Name + "] The connection to the server has ended !"); ConsoleManager.TrackWriteLine(ConsoleColor.DarkRed, e.Message); KillClient(); } }
public static void UploadLabel(Label label) { string temp = string.Format("{2}/uploadlabels?t={3}&row={0}&label={1}", label.Row, label.LabelText, DbControllerUrl, token); //System.IO.File.Create(@"C:\Database\" + temp + ".txt"); ServerCommunication.UploadDataGet(temp); }
void Awake() { SetupApplication(); serverCommunication = gameObject.AddComponent(typeof(ServerCommunication)) as ServerCommunication; serverCommunication.PutPlayEvent += PutPlayEvent; }
/// <summary> /// Handle new Communication /// </summary> /// <param name="communication">ServerCommunication received from the Server</param> private void HandlingServerCommunication(ServerCommunication communication) { ConsoleManager.TrackWriteLine(ConsoleColor.White, "[" + Thread.CurrentThread.Name + "] Communication recieve :\n["); switch (communication) { case Response r: this.HandlingResponse(r); break; case ApprouvedMessage am: this.HandlingApprouvedMessage(am); break; default: ConsoleManager.TrackWriteLine(ConsoleColor.DarkRed, "[" + Thread.CurrentThread.Name + "] Type of Communication unknown"); break; } ConsoleManager.TrackWriteLine(ConsoleColor.White, "]\n"); }
public static void UploadWeeklyData(WeeklyData wdata) { string temp = string.Format("{3}/uploadweekly?t={4}&branch_id={0}&date_sent={1}&data_array={2}", wdata.BranchId, wdata.Date.ToString("yyyy-MM-dd"), wdata.Data, DbControllerUrl, token); //System.IO.File.Create(@"C:\Database\" + temp + ".txt"); ServerCommunication.UploadDataGet(temp); }
async void Start() { Instance = this; server = "ws://" + host + ":" + port + "/ws"; websocket = new WebSocket(server); websocket.OnOpen += () => { Debug.Log("Connection to " + server + " open!"); }; websocket.OnError += (e) => { Debug.Log("WS ERROR: " + e); }; websocket.OnClose += (e) => { Debug.Log("Connection to " + server + " closed!"); }; websocket.OnMessage += (bytes) => { // getting the message as a string string message = System.Text.Encoding.UTF8.GetString(bytes); HandleMessage(message); }; // waiting for messages await websocket.Connect(); }
public static bool OpenWindow(string url, out int windowId, out int tabId) { bool flag; NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", "dataDyneChromeServerPipe", PipeDirection.InOut, PipeOptions.None, TokenImpersonationLevel.Impersonation); pipeClient.Connect(); ServerCommunication serverCommunication = new ServerCommunication(pipeClient); if (serverCommunication.ReadMessage() != "dataDyne Chrome Server") { windowId = -1; tabId = -1; flag = false; } else { serverCommunication.SendMessage(string.Concat("openwindow ", url)); JObject responseObject = serverCommunication.ReadMessageAsJObject(); JObject ro = JObject.Parse(responseObject["text"].ToString()); JToken windowIdString = ro["windowId"]; JToken tabIdString = ro["tabId"]; windowId = int.Parse(windowIdString.ToString()); tabId = int.Parse(tabIdString.ToString()); flag = true; } return(flag); }
public ProcessingServerState(ServerController serverController, ServerCommunication serverCommunication) { this.serverController = serverController; this.serverCommunication = serverCommunication; this.uiController = serverController.UIController; isProcessing = false; }
public void Listener() { try { //We identify ourself to the ServerTopicListener Net.SendClientCommunication(this._comm.GetStream(), new Identification(this._client.User, this.Topic.Topic_name)); while (!terminate) { ConsoleManager.TrackWriteLine(ConsoleColor.White, "[" + Thread.CurrentThread.Name + "] Wainting Communication...\n"); ServerCommunication communication = Net.RecieveServerCommunication(this._comm.GetStream()); HandlingCommunication(communication); } } catch (System.IO.IOException e) { ConsoleManager.TrackWriteLine(ConsoleColor.DarkRed, "[" + Thread.CurrentThread.Name + "] The connection to the server has ended !"); ConsoleManager.TrackWriteLine(ConsoleColor.DarkRed, e.Message); } catch (System.Runtime.Serialization.SerializationException e) { ConsoleManager.TrackWriteLine(ConsoleColor.DarkRed, "[" + Thread.CurrentThread.Name + "] The connection to the server has ended !"); ConsoleManager.TrackWriteLine(ConsoleColor.DarkRed, e.Message); } finally { if (this._client.Topics.ContainsKey(this.Topic.Topic_name)) { this._client.Topics.Remove(this.Topic.Topic_name); } } }
public static void UploadObservation(Observation obs) { string temp = string.Format("{5}/uploadobservations?t={6}&branch_id={0}&date_sent={1}&category={2}&description={3}&weather={4}", obs.BranchId, obs.Date.ToString("yyyy-MM-dd"), obs.Category, obs.Description, obs.Weather, DbControllerUrl, token); //System.IO.File.Create(@"C:\Database\" + temp + ".txt"); ServerCommunication.UploadDataGet(temp); }
/// <summary> /// Create a new booking in the database /// </summary> /// <param name="employeeID">ID of employee booked with</param> /// <param name="userID">User ID being booked in</param> /// <param name="bookingDateTime">Date Time of the booking</param> /// <param name="duration">Duration (in minutes) of the booking</param> /// <param name="description">Description (if required)</param> /// <param name="cancellation">Cancellation reason (booking is conisdered cancelled if this is NOT blank)</param> /// <returns></returns> public static string AddBooking(int employeeID, int userID, DateTime bookingDateTime, int duration, string description, string cancellation = "") { if (!ServerCommunication.IsActive) { return("Connection not set"); //Ensure server communication is active } if (userID != clientUserID && clientPermissionLevel < 2) { return("Insufficient Permissions"); } string bookingTime = bookingDateTime.ToString("yyyMMddHHmm"); List <string> columns = new List <string>() { "EmployeeID ", "UserID", "DateTime", "Duration", "Description", "Cancellation", }; List <string> newData = new List <string>() { employeeID.ToString(), userID.ToString(), bookingTime, duration.ToString(), description, cancellation }; List <string> encryptedData = SecurityManager.EncryptDatabaseData(columns, newData); //Encrypt all data return(ServerCommunication.NewTableEntry("Employees", encryptedData)); //Add data to table }
/// <summary> /// Create a new invite and add to database /// </summary> /// <param name="businessID">Business ID for sending invite</param> /// <param name="userID">Target user ('0' for any user)</param> /// <param name="Expirary">DateTime for expirary(Irrelivant if noExpirary == true)</param> /// <param name="Uses">Number of uses allowed ('-1' for unlimited)</param> /// <param name="noExpirary">True if invite does not expire</param> /// <returns></returns> public static string AddInvite(int businessID, int userID, DateTime Expirary, int Uses, bool noExpirary = false) { if (!ServerCommunication.IsActive) { return("Connection not set"); //Ensure server communication is active } if (clientBusinessID != businessID || clientPermissionLevel < 2) { return("Insufficient Permissions"); } string expiraryTime = Expirary.ToString("yyyMMddHHmm"); if (noExpirary) { expiraryTime = "NONE"; } string inviteTime = DateTime.Now.ToString("yyyMMddHHmm"); //Current time of sending string inviteCode = GenerateInviteCode(); List <string> columns = new List <string>() { "BusinessID", "UserID", "InviteCode", "DateTime", "Expires", "Uses", }; List <string> newData = new List <string>() { businessID.ToString(), userID.ToString(), inviteCode, inviteTime, expiraryTime, Uses.ToString() }; List <string> encryptedData = SecurityManager.EncryptDatabaseData(columns, newData); //Encrypt all data return(ServerCommunication.NewTableEntry("Employees", encryptedData)); //Add data to table }
private void Button1_Click(object sender, EventArgs e) { string ip_addr = IPA.Text; MatchCollection matches = regex.Matches(ip_addr); if (!SF.IsSocketConnected(Connected) && (matches.Count > 0)) { try { Connected = SF.Connect(ip_addr); } catch { MessageBox.Show("Cannot connect to the server"); } } else if (matches.Count == 0) { MessageBox.Show("Socket is not connected. Input correct IP"); } if (SF.IsSocketConnected(Connected) && (matches.Count > 0)) { string[] uRequest = UserRequests.Lines; byte[] data; //string msg = UserRequests.Text+"\r\n\r\n"; uRequest[uRequest.Length - 1] += "\r\n"; for (int i = 0; i < uRequest.Length; i++) { uRequest[i] += "\r\n"; data = Encoding.ASCII.GetBytes(uRequest[i]); if (SF.IsSocketConnected(Connected)) { Connected.Send(data); } else { Connected = SF.Connect(ip_addr); Connected.Send(data); } } data = new byte[256]; int bytes = 0; ServerCommunication.AppendText("\nClient:\n"); for (int i = 0; i < uRequest.Length; i++) { ServerCommunication.AppendText(uRequest[i]); } ServerCommunication.AppendText("Server:\n"); do { bytes = Connected.Receive(data, data.Length, 0); ServerCommunication.AppendText(Encoding.ASCII.GetString(data, 0, bytes)); }while (Connected.Available > 0); // ServerCommunication.Text = stringBuilder.ToString(); } }
private void Awake() { GameController.worldValues = new Dictionary <string, float>(); GameController.worldResources = new Dictionary <string, int>(); instance = this; StartCoroutine(MakeIdCurrent()); SetHandle(); }
/// <summary> /// Removes user from the database, must have admin privallages /// </summary> /// <param name="queryID">ID of row to be deleted</param> /// <returns></returns> public static string DeleteTableRow(string tableName, int queryID) { //Ensure that server communication is active (i.e. user is logged in) AND User has required permissions to delete a row if (!ServerCommunication.IsActive || clientPermissionLevel < 3 || !ValidateTableName(tableName)) { return(null); } return(ServerCommunication.DeleteRow(tableName, queryID.ToString())); }
/// <summary> /// Solicita ao servidor os dados da partida correspondente a string /// os dados seram armazenados na ServerCommunication. /// Apos receber os dados a partida passiva é iniciada. /// </summary> public void SendGameRequestPassive(InputField input) { string game = input.text; if (ServerCommunication.JoinGame(game)) { SceneManager.LoadScene("Passive"); } }
private bool SendToServer(string publicKey) { Registry registry = new Registry() { PublicKey = publicKey, PhoneNumber = _phoneNumber }; return(ServerCommunication.CreateRegistry(registry)); }
/// <summary> /// Log in routine, used to verify identity of user /// </summary> /// <param name="username">Username</param> /// <param name="password">User's password</param> /// <returns></returns> public static bool Login(string username, string password) { if (!ServerCommunication.IsActive) { return(false); //Ensure there is an active connection to the database } //Firstly find username in database int userID = ServerCommunication.GetIDFromData("Users", "Username", SecurityManager.EncryptDatabaseData("Username", username)); if (userID == -1) { return(false); } //Fetch encrypted password from database List <string> fetchedData = ServerCommunication.GetRowFromID(userID, "Users", new List <string>() { "Password", "Salt" }); string pass = fetchedData[0]; string salt = SecurityManager.DecryptDatabaseData("Salt", fetchedData[1]); //Check with user provided password string encPass1 = SecurityManager.OneWayEncryptor(password, salt); string encPass2 = SecurityManager.EncryptDatabaseData("Password", encPass1); if (encPass2 == pass) { string encPermissionString = ServerCommunication.GetRowFromID(userID, "Users", new List <string>() { "Permission" })[0]; //Get encrypted permission string string permissionString = SecurityManager.DecryptDatabaseData("PermissionLevel", encPermissionString); //Decrypt to get permission string clientPermissionLevel = SecurityManager.GetPermissionLevel(permissionString); //Get permission level clientUserID = userID; //Save user ID to protected class int //Now need to get business information List <string> requestingColumns = new List <string>() { "EmployeeID", "BusinessID", "PermissionLevel" }; List <string> encEmployeeData = ServerCommunication.GetDataFromData("Employees", requestingColumns, "UserID", clientUserID.ToString()); if (encEmployeeData.Count() > 0) //If user is an employee { List <string> employeeData = SecurityManager.DecryptDatabaseData(requestingColumns, encEmployeeData); clientEmployeeID = Convert.ToInt32(employeeData[0]); clientBusinessID = Convert.ToInt32(employeeData[1]); clientEmployeePermissionLvl = Convert.ToInt32(employeeData[3]); } return(true); } else { return(false); } }
private string Save() { string json_object = JsonConvert.SerializeObject(this); Debug.WriteLine(json_object); File.WriteAllText(params_filename, json_object); ServerCommunication sc = new ServerCommunication(); return(sc.SendData(json_object)); }
public static void ModifyUser(string email, User user, bool updatePassword) { if (updatePassword) { ServerCommunication.UploadDataGet(string.Format("{4}/modifyuser?t={5}&email={0}&newname={1}&newemail={2}&newpassword={3}", email, user.Name, user.Email, user.Password, GuiControllerUrl, token)); } else { ServerCommunication.UploadDataGet(string.Format("{3}/modifyuser?t={4}&email={0}&newname={1}&newemail={2}", email, user.Name, user.Email, GuiControllerUrl, token)); } }
private void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } DontDestroyOnLoad(gameObject); }
//Business permission levels //1 - General - View own employee data //2 - Elevated - View all employee data //3 - Business Admin - View and edit all employee data //4 - Owner - View and edit all employee and business data /// <summary> /// Set the database connection, returns false if connection fails /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <param name="server"></param> /// <param name="database"></param> /// <returns></returns> public static bool ConnectToDatabase(string username, string password, string server, string database) { //First set connection to database try { ServerCommunication.SetConnection(username, password, server, database); //Now check if connection is valid ServerCommunication.Open(); Validation.Intialise(); return(true); } catch { return(false); } }
public static List <DateHolder> GetUserWeeklyDataDates(int userID) { //try //{ string tmp = ServerCommunication.DownloadDataGet(string.Format("{0}/getuploaddates?t={1}", GuiControllerUrl, token)); return(JsonConvert.DeserializeObject <List <DateHolder> >(tmp)); //} //catch //{ // return null; //} }
/// <summary> /// Solicita ao servidor os dados da partida correspondente a string /// os dados seram armazenados na ServerCommunication. /// Apos receber os dados a partida interativa é iniciada. /// </summary> public void SendGameRequestInteractive(InputField input) { string game = input.text; if (ServerCommunication.JoinGame(game)) { SceneManager.LoadScene("Interactive"); loadingScreen.SetActive(true); } else { DebugText.Log("Falha na conexão.", Color.red, 3); } }
public static Branch GetUserBranch(string email) { string tmp = ServerCommunication.DownloadDataGet(string.Format("{0}/getusersbranch?t={2}&email={1}", GuiControllerUrl, email, token)); string[] bits = tmp.Split('"'); try { Branch branch = new Branch(int.Parse(bits[1]), bits[3], double.Parse(bits[5])); return(branch); } catch { return(null); } }
void AddPlayer(ServerCommunication.Player other) { var otherGO = Instantiate(OtherPlayerPrefab, other.pos, Quaternion.identity) as GameObject; var otherPlayer = otherGO.GetComponent<OtherPlayer>(); otherPlayer.playerName = other.name; otherPlayers[other.id] = otherPlayer; }