Exemple #1
0
    void Start()
    {
        socket = GetComponent <SocketIOComponent>();

        // This line will set up the listener function
        socket.On("connectionEstabilished", onConnectionEstabilished);
        socket.On("foreignMessage", onForeignMessage);
        socket.On("playerConnection", onPlayerConnection);
        socket.On("playerDisconnection", onPlayerDisconnection);
        socket.On("sendCard", onNewHandDistributed);
        socket.On("otherCard", onOtherCardDistributed);
        socket.On("roleAssigment", onRoleAssignement);
        socket.On("gameStarted", onStartGame);
        socket.On("cardHover", onCardHover);
        socket.On("revealCard", onCardReveal);
        socket.On("token", onTokenDistributed);
        socket.On("newTurnAvailable", onNewTurnAvailable);
        socket.On("newTurn", onNewTurn);
        socket.On("endTurn", onEndTurn);
        socket.On("defausse", onDefausseSent);
        socket.On("handFlip", onPlayerHandFlip);
        socket.On("allHandFlipped", onAllHandFlipped);
        socket.On("GoodGuysWin", onGoodGuysWin);
        socket.On("BadGuysWin", onBadGuysWin);

        timeBomb  = GameObject.Find("GameManager").GetComponent <TimeBomb>();
        uiManager = GameObject.Find("GameManager").GetComponent <UIManager>();
    }
        public APIMessageView UpdateTimebombStatus(TimeBomb timebomb, int status)
        {
            APIMessageView results = new APIMessageView();

            try
            {
                // Retrieve bomb with id i
                TimeBomb defuseBomb = _context.TimeBombs.FirstOrDefault(x => x.TimeBombId == timebomb.TimeBombId);

                // Examine bomb's status to ensure it is armed
                if (defuseBomb.Status != status)
                {
                    string encryptedMessage = EncryptionMethods.encrypt(EncryptionMethods.crocodile(), timebomb.KillMessage, EncryptionMethods.alphabet());

                    // Hash killmessage and compare it to bomb's message
                    if (encryptedMessage.Equals(defuseBomb.KillMessage))
                    {
                        System.Console.WriteLine("Success! KillMessages match!");

                        // If match, set bomb status to -1
                        defuseBomb.UpdatedAt = DateTime.Now;
                        defuseBomb.Status    = status;
                        _context.SaveChanges();

                        results.TimeBomb = defuseBomb;
                        string stringStatus = getTimebombStatus(status);

                        System.Console.WriteLine($"Success! Timebomb set to: {stringStatus}!");
                        results.Success = true;
                        results.Message = $"Success! Timebomb set to: {stringStatus}!";
                    }
                    else
                    {
                        System.Console.WriteLine("Failure! KillMessages do not match!");
                        results.Success = false;
                        results.Message = "Failure! KillMessages do not match!";
                    }
                }
                else
                {
                    System.Console.WriteLine($"Error! Timebomb cannot set status to {status}! Status already set to {status}");
                    results.Success = false;
                    results.Message = $"Error! Timebomb cannot set status to {status}! Status already set to {status}";
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Something's f****d!");
                System.Console.WriteLine(e);
                results.Success = false;
                results.Message = "An error occured! " + e;
            }

            return(results);
        }
 public static string validateTimebombDefuse(TimeBomb valid)
 {
     if (valid.TimeBombId == 0)
     {
         return("TimeBombId");
     }
     else if (string.IsNullOrEmpty(valid.KillMessage))
     {
         return("KillMessage");
     }
     else
     {
         return("");
     }
 }
        public IActionResult NewTimeBomb([FromBody] SecretView timebomb)
        {
            APIResponseView results = new APIResponseView();

            if (ModelState.IsValid)
            {
                try
                {
                    TimeBomb newTimeBomb = timebomb.NewTimeBomb;

                    newTimeBomb.CreatedAt = DateTime.Now;
                    newTimeBomb.UpdatedAt = DateTime.Now;

                    string encryptedMessage = EncryptionMethods.encrypt(EncryptionMethods.crocodile(), newTimeBomb.KillMessage, EncryptionMethods.alphabet());

                    newTimeBomb.KillMessage = encryptedMessage;

                    _context.Add(newTimeBomb);
                    _context.SaveChanges();

                    System.Console.WriteLine("Success! Adding timebomb with id " + newTimeBomb.TimeBombId);

                    _context.SaveChanges();

                    results.Success = true;
                    results.Message = "Success! Adding timebomb with id " + newTimeBomb.TimeBombId;
                }
                catch (Exception e)
                {
                    System.Console.WriteLine("Something's f****d!");
                    System.Console.WriteLine(e);
                    results.Success = false;
                    results.Message = "An error occured! " + e;
                }
            }
            else
            {
                results.Success = false;
                string message = "Errant input! Model not valid!";
                results.Message = message;
                System.Console.WriteLine(message);
            }

            return(Json(results));
        }
        public string detonate(TimeBomb bomb)
        {
            try
            {
                // Decrypts timebomb message
                string decrypt = EncryptionMethods.decrypt(bomb.Message.MessageBody, bomb.MessageCypher, EncryptionMethods.alphabet());
                System.Console.WriteLine(decrypt);

                // Detonates bomb by emailing message to bomb.address

                bomb.Status = 1;
                _context.SaveChanges();

                return($"Success! Bomb with id {bomb.TimeBombId} detonated!");
            }
            catch (System.Exception e)
            {
                bomb.Status = -2;
                _context.SaveChanges();

                return($"Errant operation detonating bomb with id {bomb.TimeBombId}! Error: " + e.Message);
            }
        }
Exemple #6
0
        public FwkTask(XmlNode node, string testName,
                       UnitFnMethod <FwkTask, ClientBase> taskStartedHandler,
                       UnitFnMethod <FwkTask, ClientBase, Exception> taskDoneHandler)
        {
            if (node == null)
            {
                throw new IllegalArgException("Null node for FwkTask constructor.");
            }

            #region Read the attributes

            string taskName     = string.Empty;
            string containerStr = null;
            string methodName   = null;
            string typeAttrib   = null;
            m_timesToRun      = 1;
            m_threadCount     = 1;
            m_parallel        = false;
            m_timeoutMillis   = DefaultTimeoutMillis;
            m_continueOnError = false;
            m_class           = null;

            XmlAttributeCollection xmlAttribs = node.Attributes;
            if (xmlAttribs != null)
            {
                foreach (XmlAttribute xmlAttrib in xmlAttribs)
                {
                    switch (xmlAttrib.Name)
                    {
                    case NameAttrib:
                        taskName = xmlAttrib.Value;
                        break;

                    case ArgTypes:
                        typeAttrib = xmlAttrib.Value;
                        break;

                    case ContainerAttrib:
                        containerStr = xmlAttrib.Value;
                        break;

                    case MethodAttrib:
                        methodName = xmlAttrib.Value;
                        break;

                    case TimesToRunAttrib:
                        m_timesToRun = XmlNodeReaderWriter.String2Int(xmlAttrib.Value, 1);
                        break;

                    case ThreadCountAttrib:
                        m_threadCount = XmlNodeReaderWriter.String2Int(xmlAttrib.Value, 1);
                        break;

                    case ParallelAttrib:
                        m_parallel = XmlNodeReaderWriter.String2Bool(xmlAttrib.Value, false);
                        break;

                    case WaitTimeAttrib:
                        m_timeoutMillis = XmlNodeReaderWriter.String2Seconds(xmlAttrib.Value,
                                                                             DefaultTimeoutMillis) * 1000;
                        break;

                    case ContinueAttrib:
                        m_continueOnError = XmlNodeReaderWriter.String2Bool(xmlAttrib.Value, false);
                        break;

                    case ClassAttrib:
                        m_class = xmlAttrib.Value;
                        break;

                    default:
                        throw new IllegalArgException("Unknown attribute '" +
                                                      xmlAttrib.Name + "' found in '" + node.Name +
                                                      "' node.");
                    }
                }
            }
            int taskNum = 1;
            if (m_GlobalTaskNames.ContainsKey(taskName))
            {
                taskNum = m_GlobalTaskNames[taskName] + 1;
            }
            m_GlobalTaskNames[taskName] = taskNum;
            taskName += '_' + taskNum.ToString();

            #endregion

            m_timeBomb          = new TimeBomb();
            m_timeBomb.TaskName = testName + '.' + taskName;

            #region Create a delegate by loading the assembly

            Assembly loadAssmb = null;
            string   typeName  = null;
            if (containerStr != null && methodName != null)
            {
                object inst = null;
                int    dotIndx;
                if ((dotIndx = containerStr.IndexOf('.')) < 0)
                {
                    Type myType = this.GetType();
                    loadAssmb = myType.Assembly;
                    typeName  = myType.Namespace + '.' + containerStr;
                    Util.Log(Util.LogLevel.Info, "Assembly {0} loaded and typename is {1}", loadAssmb, typeName);
                }
                else
                {
                    string assmbName = containerStr.Substring(0, dotIndx);
                    if (!m_AssemblyMap.TryGetValue(assmbName, out loadAssmb))
                    {
                        try
                        {
                            loadAssmb = Assembly.Load(assmbName);
                            Util.Log(Util.LogLevel.Info, "Assembly {0} loaded ", assmbName);
                        }
                        catch (Exception e)
                        {
                            throw new IllegalArgException("Cannot load assembly '" +
                                                          assmbName + "' for task: " + m_timeBomb.TaskName +
                                                          " exception: " + e);
                        }
                        m_AssemblyMap.Add(assmbName, loadAssmb);
                    }
                    typeName = containerStr.Substring(dotIndx + 1);
                }
                //string typeAttrib;
                if (loadAssmb != null)
                {
                    if (typeAttrib == null)
                    {
                        inst = loadAssmb.CreateInstance(typeName, true);
                    }
                    else
                    {
                        //typeAttrib = "Apache.Geode.Client.Tests.ArrayOfByte,Apache.Geode.Client.Tests.ArrayOfByte";
                        //typeAttrib = "System.int,System.Int32";
                        string[] typeNames   = typeAttrib.Split(',');
                        string   mangledName = typeName + "`" + typeNames.Length.ToString();

                        //Type type = loadAssmb.GetType(mangledName, true, true);
                        Type[] types = new Type[typeNames.Length];
                        for (int index = 0; index < typeNames.Length; ++index)
                        {
                            string typName = typeNames[index].Trim();
                            if (typName == "int" || typName == "Int32" || typName == "string" ||
                                typName == "String" || typName == "byte[]" || typName == "Byte[]" ||
                                typName == "string[]" || typName == "String[]" || typName == "Object" ||
                                typName == "object")
                            {
                                if (typName.Equals("int"))
                                {
                                    typName = "Int32";
                                }
                                else if (typName.Equals("string"))
                                {
                                    typName = "String";
                                }
                                else if (typName.Equals("string[]"))
                                {
                                    typName = "String[]";
                                }
                                else if (typName.Equals("byte[]"))
                                {
                                    typName = "Byte[]";
                                }
                                else if (typName.Equals("object"))
                                {
                                    typName = "Object";
                                }
                                typName = "System." + typName;
                                //Util.Log("rjk: FwkTask: typeAttrib 33 argname {0}", typName);
                                types[index] = Type.GetType(typName.Trim());
                                //Util.Log("rjk: FwkTask: typeAttrib 34 argname {0}", typName);
                            }
                            else
                            {
                                typName      = "Apache.Geode.Client.Tests." + typName;
                                types[index] = loadAssmb.GetType(typName.Trim(), true, true);
                                //Util.Log("rjk: FwkTask: typeAttrib for userobject 34 argname {0}", typName);
                            }
                        }

                        Type type = loadAssmb.GetType(mangledName, true, true).MakeGenericType(types);
                        inst = type.GetConstructor(System.Type.EmptyTypes).Invoke(null);
                    }
                }
                if (inst != null)
                {
                    try
                    {
                        MethodInfo mInfo = inst.GetType().GetMethod(methodName,
                                                                    BindingFlags.IgnoreCase | BindingFlags.Public |
                                                                    BindingFlags.Static | BindingFlags.FlattenHierarchy |
                                                                    BindingFlags.Instance);
                        m_delegate = Delegate.CreateDelegate(typeof(UnitFnMethod), inst,
                                                             mInfo, true);
                    }
                    catch (Exception ex)
                    {
                        throw new IllegalArgException(
                                  "Exception while creating delegate [" + methodName + "]: " + ex);
                    }
                    m_pushTaskNameDelegate = Delegate.CreateDelegate(
                        typeof(UnitFnMethod <string>), inst, PushTaskNameMethod, true);
                    m_endDelegate = Delegate.CreateDelegate(
                        typeof(UnitFnMethod), inst, EndTaskMethod, true);
                }
            }
            if (m_delegate == null)
            {
                throw new IllegalArgException("Cannot create delegate '" +
                                              methodName + "' for task: " + m_timeBomb.TaskName);
            }

            #endregion

            #region Add the clients

            m_clients     = new List <string>();
            m_clientGroup = new ClientGroup(false);
            m_clients     = FwkClient.ReadClientNames(node, false);
            List <ClientBase> clients = FwkClient.GetClients(m_clients);
            m_clientGroup.Add(clients);
            m_timeBomb.AddClients(new ClientBase[] { m_clientGroup });
            m_taskStartedHandler = taskStartedHandler;
            m_taskDoneHandler    = taskDoneHandler;
            int clientCount = m_clients.Count;

            #endregion

            #region Add any data

            m_localDataNames = new List <string>();
            Dictionary <string, FwkData> data = FwkData.ReadDataNodes(node);
            // Task specific data is written as <taskname>.<key> to avoid
            // overwriting the global data, since that needs to be preserved
            // across tasks.
            if (m_threadCount > 1)
            {
                // We shall treat 'threadCount' and 'numThreads' as equivalent,
                // i.e. if 'threadCount' is defined for a task then 'numThreads'
                // shall also be written as data.
                foreach (string threadKey in ThreadCountKeys)
                {
                    m_localDataNames.Add(threadKey);
                    Util.BBSet(Name, threadKey,
                               new FwkData(m_threadCount.ToString(), null, DataKind.String));
                }
            }
            if (clientCount > 0)
            {
                // Overwrite the clientCount (if any) with the actual value.
                Util.BBSet(Name, ClientCountKey,
                           new FwkData(clientCount.ToString(), null, DataKind.String));
            }
            foreach (KeyValuePair <string, FwkData> pair in data)
            {
                m_localDataNames.Add(pair.Key);
                Util.BBSet(Name, pair.Key, pair.Value);
            }

            #endregion
        }