Ejemplo n.º 1
0
        /// <summary>
        /// Client want to modify an object
        /// </summary>
        /// <param name="idClient">Id of the client</param>
        /// <param name="id">Id of the object to be modified</param>
        /// <param name="str">String representation of the new version of the object</param>
        public void do_modif(int idClient, int id, String str)
        {
            //One client at a time access "clients"
            Monitor.Enter(clients);

            //Cerating the new version of the object from str
            BoardElement b = ObjectConverter.reconvertElement(id, str);

            if (clients[idClient].ObjectLocked == id) //If the client has the lock on the object
            {
                allBoardElements[id] = b;
                foreach (ClientInterface client in clients.Values)
                {
                    //We update the value for each client
                    client.send_add(id, allBoardElements[id]);
                }
            }
            else
            {
                //Strange things happens, a client tried to access forbidden data
                //to avoid any missunderstanding, we resend all information to the client
                do_reset_client(idClient);
            }
            Monitor.Exit(clients);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Client add an object
        /// </summary>
        /// <param name="idClient">Id of the client</param>
        /// <param name="str">String representing the object</param>
        public void do_add(int idClient, String str)
        {
            //One client at a time access "clients"
            Monitor.Enter(clients);

            //Creating an object with id acutalID from string str
            BoardElement b = ObjectConverter.reconvertElement(actualID, str);

            //Adding the object
            allBoardElements.Add(actualID, b);
            foreach (ClientInterface client in clients.Values)
            {
                //telling all clients to add the object
                client.send_add(b.m_id, b);
            }

            //The minimum unatributed ID is increasing as we added an object
            actualID++;
            Monitor.Exit(clients);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Method to send the instruction to the client to add an object
 /// </summary>
 /// <param name="id">Id of the object</param>
 /// <param name="b">Elemnt to be added</param>
 public void send_add(int id, BoardElement b)
 {
     connexionClient.addInstruction("ADD" + Convert.ToString(id) + " " + b.GetString());
     //                              add      with id "id"           the object b
 }