Exemplo n.º 1
0
    public void JoinParty(PartyInfo party)
    {
        JoinCommand cmd = new JoinCommand();

        cmd.type      = (int)CommandType.JOIN;
        cmd.partyName = party.partyName;
        cmd.player    = curPlayer;
        string jsonCmd = JsonUtility.ToJson(cmd);

        currentSocket.Send(jsonCmd);
    }
Exemplo n.º 2
0
        public async Task <GameState> Handle(Guid tableId, JoinCommand command)
        {
            Task <GameState> loadStateTask = _reader.LoadTableState(tableId);

            await loadStateTask;

            GameState currentState = loadStateTask.Result;
            GameState newState     = CommandsHandler.Handle(currentState, command);

            await _writer.WriteGameState(newState);

            return(newState);
        }
Exemplo n.º 3
0
        private void OnClick(object sender, RoutedEventArgs e)
        {
            if (With is TLChannel channel)
            {
                if (channel.IsLeft)
                {
                    JoinCommand?.Execute(null);
                }
                else if (channel.HasBannedRights && channel.BannedRights.IsViewMessages)
                {
                    DeleteAndExitCommand?.Execute(null);
                }
                else
                {
                    if (channel.IsBroadcast)
                    {
                        if (channel.IsCreator || (channel.HasAdminRights && channel.AdminRights.IsPostMessages))
                        {
                        }
                        else
                        {
                            ToggleMuteCommand?.Execute(null);
                        }
                    }
                }
            }

            if (With is TLChatForbidden forbiddenChat)
            {
                DeleteAndExitCommand?.Execute(null);
            }

            if (With is TLUser user)
            {
                var full = InMemoryCacheService.Current.GetFullUser(user.Id);
                if (full != null && full.IsBlocked)
                {
                    UnblockCommand?.Execute(null);
                }

                if (user.IsBot && HasAccessToken)
                {
                    StartCommand?.Execute(null);
                }

                if (user.IsDeleted)
                {
                    DeleteAndExitCommand?.Execute(null);
                }
            }
        }
Exemplo n.º 4
0
    public void JoinRoomClick()
    {
        Debug.Log("User Display Name: " + ClientContext.Instance.GetUserSession().GetUserInfo().GetDisplayName());
        Debug.Log("User Id : " + ClientContext.Instance.GetUserSession().GetUserInfo().GetUserId());
        Debug.Log("Auth token Id : " + ClientContext.Instance.GetUserSession().GetAuthToken());


        // TODO: Build Command from builder
        IRoomService roomService = new RoomService();
        ICommand     command     = new JoinCommand(roomService.findRoom(), ClientContext.Instance.GetUserSession().GetAuthToken());

        EventDispatcher dispatcher = new EventDispatcher();

        dispatcher.addListener(EventType.JOINED_ROOM_SUCCESS, new JoinRoomHandler(ClientContext.Instance.GetUserSession()));
        command.perform(dispatcher);
    }
Exemplo n.º 5
0
        private async Task When(JoinCommand cmd)
        {
            _group = await Group.AddAsync(cmd.RoomName);

            var application = _applications.GetOrAdd(cmd.RoomName,
                                                     newRoomName => new ARWorldApplication(newRoomName, new EventStore(), new DomainEventPublisher()));

            _roomName = cmd.RoomName;

            application.DomainEventPublisher.EventStream
            .Subscribe(e =>
            {
                switch (e)
                {
                case PlayerJoined joined:
                    BroadcastToSelf(_group).OnEvent(joined);
                    Console.WriteLine($"joined: {joined.PlayerId} as {joined.PlayerName} to {joined.RoomName}");
                    break;

                case PlayerLeft left:
                    BroadcastToSelf(_group).OnEvent(left);
                    Console.WriteLine($"left: {left.PlayerId}");
                    break;

                case PlayerSpoke playerSpoke:
                    BroadcastToSelf(_group).OnEvent(playerSpoke);
                    Console.WriteLine($"spoke: {playerSpoke.PlayerId} like {playerSpoke.Message}");
                    break;

                case PlayerMoved playerMoved:
                    BroadcastToSelf(_group).OnEvent(playerMoved);
                    // Console.WriteLine($"spoke: {playerSpoke.PlayerId} like {playerSpoke.Message}");
                    break;
                }
            }).AddTo(_disposables);

            application.Execute(cmd);

            BroadcastToSelf(_group).OnEvent(
                new ARWorldEventStream()
            {
                RoomName    = _roomName,
                EventStream = application.EventStore.LoadEventStream()
            });
        }
Exemplo n.º 6
0
        private void connectButton_Click(object sender, EventArgs e)
        {
            JoinCommand join = new JoinCommand();
            join.UserName = "******";
            join.PasswordHash = Communication.Tools.HashString("dani");
            try
            {
                requestID = serviceProxy.HandleDarPoolingMobileRequest(join);
                //MessageBox.Show(response);
                if (requestID != null)
                    connectionLabel.Text = "Request sent";

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 7
0
        private void connectButton_Click(object sender, EventArgs e)
        {
            JoinCommand join = new JoinCommand();

            join.UserName     = "******";
            join.PasswordHash = Communication.Tools.HashString("dani");
            try
            {
                requestID = serviceProxy.HandleDarPoolingMobileRequest(join);
                //MessageBox.Show(response);
                if (requestID != null)
                {
                    connectionLabel.Text = "Request sent";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 8
0
        public override bool Join(UserNodeCore context, string username, string password,
                                  string serviceNodeAddress, string callbackAddress)
        {
            try
            {
                ClientCallback callback = new ClientCallback(context);

                // First of all, set up the connection
                EndpointAddress   endPointAddress = new EndpointAddress(serviceNodeAddress);
                WSDualHttpBinding binding         = new WSDualHttpBinding();
                binding.ClientBaseAddress = new Uri(callbackAddress);
                DuplexChannelFactory <IDarPooling> factory = new DuplexChannelFactory <IDarPooling>(
                    callback, binding, endPointAddress);
                context.ServiceProxy = factory.CreateChannel();
            }
            catch
            {
                context.ServiceProxy = null;
                return(false);
            }

            // Now, hopefully you have a working ServiceProxy.
            string  passwordHash = Communication.Tools.HashString(password);
            Command c            = new JoinCommand(context.UserNode, username, passwordHash);

            try
            {
                context.ServiceProxy.HandleDarPoolingRequest(c);
            }
            catch (TimeoutException e)
            {
                context.ServiceProxy = null;
                throw e;
            }

            // Finally, if Join is NOT successfull, remove reference (UserNodeCore.onResultReceive)
            return(true);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Creates a new instance of an On Join command
 /// </summary>
 /// <param name="type">The type of join command</param>
 /// <param name="value">The value for the command (download link, website url)</param>
 public OnJoinCommand(JoinCommand type, object value)
 {
     this.Type  = type;
     this.Value = value;
 }
Exemplo n.º 10
0
 public ActionResult <GameState> Join(string tableId, [FromBody] JoinCommand joinCommand)
 {
     return(_commandFacade.Handle(Guid.Parse(tableId), joinCommand).Result);
 }
Exemplo n.º 11
0
 private void When(JoinCommand cmd)
 {
     Update(_roomName, world => world.AddPlayer(cmd.PlayerId, cmd.PlayerName));
 }
Exemplo n.º 12
0
    /**
     * <summary>
     * Parses the <see cref="CommandList"/> with the specified file name to an object
     * </summary>
     */
    public static CommandList Parse(string name = "base")
    {
        Dictionary <string, object> jsonData;

        // Check if the files Directory exists, if not, create it
        string dataPath = Application.persistentDataPath + "/commandlists";

        if (!Directory.Exists(dataPath))
        {
            Directory.CreateDirectory(dataPath);
        }

        // Read from the file, handle cases the specified file, or even the standard file doesnt exist
        if (File.Exists(dataPath + "/" + name + ".json"))
        {
            using (StreamReader sr = new StreamReader(dataPath + "/" + name + ".json"))
            {
                jsonData = JsonConvert.DeserializeObject <Dictionary <string, object> >(sr.ReadLine());
            }
        }
        else if (File.Exists(dataPath + "/base.json"))
        {
            using (StreamReader sr = new StreamReader(dataPath + "/base.json"))
            {
                jsonData = JsonConvert.DeserializeObject <Dictionary <string, object> >(sr.ReadLine());
            }
            PlayerPrefs.SetString("list", "base");
        }
        else
        {
            jsonData = new Dictionary <string, object>();
        }

        // Parse the string to an object
        CommandList newCommandList;

        if (jsonData.Count > 0)
        {
            // Try get the name of the list
            if (jsonData.TryGetValue("name", out object dataName))
            {
                newCommandList = new CommandList(name, (string)dataName);
            }
            else
            {
                newCommandList = new CommandList(name, "Some List");
            }

            // Try get the content of the list
            if (jsonData.TryGetValue("parts", out object partlistobj))
            {
                // Iterate over each PartCommandList in the JSON data
                foreach (List <Dictionary <string, object> > part in ((Newtonsoft.Json.Linq.JArray)partlistobj).ToObject <List <List <Dictionary <string, object> > > >())
                {
                    PartCommandList newPart = new PartCommandList();
                    // Iterate over each Command in that list in the JSON data
                    foreach (Dictionary <string, object> cmd in part)
                    {
                        if (cmd.TryGetValue("commandTitle", out object commandTitle))
                        {
                            // Incase there is a commandTitle specified in JSON, try and get meaning from it
                            Command newCmd = null;
                            switch (commandTitle)
                            {
                            // Incase the title means something, try and get the values for that specific Command
                            case "rainbow":
                                newCmd = new RainbowCommand();
                                if (cmd.TryGetValue("wait_ms", out object wait_ms))
                                {
                                    ((RainbowCommand)newCmd).wait_ms = Convert.ToInt32(wait_ms);
                                }
                                break;

                            case "rainbowStationary":
                                newCmd = new StatRainbowCommand();
                                if (cmd.TryGetValue("wait_ms", out wait_ms))
                                {
                                    ((StatRainbowCommand)newCmd).wait_ms = Convert.ToInt32(wait_ms);
                                }
                                break;

                            case "colorWipe":
                                newCmd = new ColorwipeCommand();
                                if (cmd.TryGetValue("color", out object color))
                                {
                                    ((ColorwipeCommand)newCmd).color = Helper.ToColor(Convert.ToInt32(color));
                                }
                                if (cmd.TryGetValue("wait_ms", out wait_ms))
                                {
                                    ((ColorwipeCommand)newCmd).wait_ms = Convert.ToInt32(wait_ms);
                                }
                                break;

                            case "setColor":
                                newCmd = new SetColorCommand();
                                if (cmd.TryGetValue("color", out color))
                                {
                                    ((SetColorCommand)newCmd).color = Helper.ToColor(Convert.ToInt32(color));
                                }
                                break;

                            case "theaterChase":
                                newCmd = new TheaterCommand();
                                if (cmd.TryGetValue("color", out color))
                                {
                                    ((TheaterCommand)newCmd).color = Helper.ToColor(Convert.ToInt32(color));
                                }
                                if (cmd.TryGetValue("wait_ms", out wait_ms))
                                {
                                    ((TheaterCommand)newCmd).wait_ms = Convert.ToInt32(wait_ms);
                                }
                                if (cmd.TryGetValue("iterations", out object iterations))
                                {
                                    ((TheaterCommand)newCmd).iterations = Convert.ToInt32(iterations);
                                }
                                break;

                            case "theaterChaseRainbow":
                                newCmd = new TheaterRainbowCommand();
                                if (cmd.TryGetValue("wait_ms", out wait_ms))
                                {
                                    ((TheaterRainbowCommand)newCmd).wait_ms = Convert.ToInt32(wait_ms);
                                }
                                break;

                            case "interpolate":
                                newCmd = new InterpolateCommand();
                                if (cmd.TryGetValue("color", out color))
                                {
                                    ((InterpolateCommand)newCmd).color = Helper.ToColor(Convert.ToInt32(color));
                                }
                                if (cmd.TryGetValue("color2", out object color2))
                                {
                                    ((InterpolateCommand)newCmd).color2 = Helper.ToColor(Convert.ToInt32(color2));
                                }
                                if (cmd.TryGetValue("duration_ms", out object duration_ms))
                                {
                                    ((InterpolateCommand)newCmd).duration_ms = Convert.ToInt32(duration_ms);
                                }
                                if (cmd.TryGetValue("goback", out object goback))
                                {
                                    ((InterpolateCommand)newCmd).goback = (bool)goback;
                                }
                                break;

                            case "wait":
                                newCmd = new WaitCommand();
                                if (cmd.TryGetValue("duration_ms", out duration_ms))
                                {
                                    ((WaitCommand)newCmd).duration_ms = Convert.ToInt32(duration_ms);
                                }
                                break;

                            case "split":
                                newCmd = new SplitCommand();
                                if (cmd.TryGetValue("newList", out object newList))
                                {
                                    ((SplitCommand)newCmd).newList = Convert.ToInt32(newList);
                                }
                                break;

                            case "join":
                                newCmd = new JoinCommand();
                                if (cmd.TryGetValue("listtojoin", out object listtojoin))
                                {
                                    ((JoinCommand)newCmd).listtojoin = Convert.ToInt32(listtojoin);
                                }
                                if (cmd.TryGetValue("waitlist", out object waitlist))
                                {
                                    ((JoinCommand)newCmd).waitlist = (bool)waitlist;
                                }
                                break;
                            }
                            // Only add to list if the title meant sth
                            if (newCmd != null)
                            {
                                if (cmd.TryGetValue("title", out object title))
                                {
                                    newCmd.title = (string)title;
                                }
                                if (cmd.TryGetValue("lamps", out object lamps))
                                {
                                    newCmd.lamps = ((Newtonsoft.Json.Linq.JArray)lamps).ToObject <List <int> >();
                                }
                                newPart.AddHidden(newCmd);
                            }
                        }
                    }
                    newCommandList.lists.Add(newPart);
                }
            }
            return(newCommandList);
        }
        return(new CommandList());
    }
Exemplo n.º 13
0
    /**
     * <summary>
     * Changes the <see cref="Command"/> object to the new dynamic type specified by newSetting
     * </summary>
     */
    public void ChangeCommand(Command cmd, string newSetting)
    {
        // Initializing the subtype
        Command newCommand;

        if (newSetting == "rainbow")
        {
            newCommand = new RainbowCommand();
        }
        else if (newSetting == "rainbowStationary")
        {
            newCommand = new StatRainbowCommand();
        }
        else if (newSetting == "theaterChaseRainbow")
        {
            newCommand = new TheaterRainbowCommand();
        }
        else if (newSetting == "theaterChase")
        {
            newCommand = new TheaterCommand();
        }
        else if (newSetting == "colorWipe")
        {
            newCommand = new ColorwipeCommand();
        }
        else if (newSetting == "interpolate")
        {
            newCommand = new InterpolateCommand();
        }
        else if (newSetting == "setColor")
        {
            newCommand = new SetColorCommand();
        }
        else if (newSetting == "wait")
        {
            newCommand = new WaitCommand();
        }
        else if (newSetting == "split")
        {
            newCommand = new SplitCommand();
        }
        else if (newSetting == "join")
        {
            newCommand = new JoinCommand();
        }
        else
        {
            newCommand = new RainbowCommand();
        }

        // Saves all settings from the old command that the new Command has
        newCommand.SaveSettings(cmd.GetSettings());

        // Replaces the old Gameobject with a fresh one and initializes it
        int idx = 0;
        int i   = 0;

        foreach (PartCommandList list in commands.lists)
        {
            if (list.list.Contains(cmd))
            {
                idx = list.Remove(cmd);
                list.list.Insert(idx, newCommand);

                i = commands.lists.IndexOf(list);
            }
        }
        GameObject obj = Instantiate(commandPrefab, commands.lists[i].listObject.transform);

        newCommand.commandObject = obj;
        newCommand.Init();

        obj.transform.SetSiblingIndex(idx);

        // Deletes the old Gameobject to be picked up by garbage collector
        GameObject.Destroy(cmd.commandObject);
    }
Exemplo n.º 14
0
 private void Join(ApplicationContext applicationContext, JoinCommand join)
 {
     applicationContext.TeamContext = new TeamContext(join.Text);
     applicationContext.Application.Server.Write(Components.LogType.Info, "joining team " + join.Text);
 }
Exemplo n.º 15
0
        private void RelayJoinCommand(object sender, JoinCommand e)
        {
            string msg = string.Format("[{0}] * {1} has joined.", e.Channel, Bot.IRC.Nickname);

            ProcessRelay(e.Channel, RelayType.Join, msg);
        }
    // Update is called once per frame
    void Update()
    {
        List <NetworkCommand> cmds = Network.getPendingCommands();

        if (cmds != null)
        {
            foreach (NetworkCommand cmd in cmds)
            {
                /*** IN-GAME ACTIONS ***/
                if (cmd is MoveCommand)
                {
                    MoveCommand move  = (MoveCommand)cmd;
                    Pos         start = Network.getPlayer(move.clientID).grid_pos;
                    Pos         end   = move.end;
                    Debug.Log("Move received! From " + start + " to " + end);

                    mapManager.move(start, end);
                }
                if (cmd is AttackCommand)
                {
                    AttackCommand attack = (AttackCommand)cmd;
                    Pos           start  = Network.getPlayer(attack.clientID).grid_pos;
                    Pos           end    = attack.end;
                    Debug.Log("Attack received! From " + start + " to " + end + " action No: " + attack.actionNo);

                    mapManager.attack(start, end, attack.actionNo);
                }
                if (cmd is WaitCommand)
                {
                    WaitCommand wait = (WaitCommand)cmd;
                    Debug.Log("Wait received! From client#" + wait.clientID);

                    Client waitingClient = Network.getPeer(wait.clientID);
                    waitingClient.playerObject.wait();
                }
                if (cmd is InteractCommand)
                {
                    InteractCommand interact = (InteractCommand)cmd;
                    Pos             start    = Network.getPlayer(interact.clientID).grid_pos;
                    Pos             end      = interact.end;
                    Debug.Log("Interact received! From " + start + " to " + end);

                    mapManager.interact(start, end);
                }
                if (cmd is UseItemCommand)
                {
                    UseItemCommand item      = (UseItemCommand)cmd;
                    Player         player    = Network.getPlayer(item.clientID);
                    Item           itemToUse = player.inventory.GetItemFromSlot(item.slotIndex);
                    player.inventory.DecrementItemAtSlot(item.slotIndex);
                    InventoryManager.UseItem(itemToUse, player);
                    Debug.Log("Use Item received! From client#" + item.clientID + " for item in slot #" + item.slotIndex);
                }
                /*** LOBBY ACTIONS ***/
                if (cmd is ReadyCommand)
                {
                    ReadyCommand ready = (ReadyCommand)cmd;
                    Debug.Log("Received READY");

                    Client client = Network.getPeer(ready.clientID);
                    if (client == null)
                    {
                        Network.setPeer(ready.clientID);
                        client = Network.getPeer(ready.clientID);
                    }
                    client.ready = !client.ready;
                }
                if (cmd is NicknameCommand)
                {
                    NicknameCommand nickname = (NicknameCommand)cmd;
                    Debug.Log("Received nickname: " + nickname.nickname);

                    Client client = Network.getPeer(nickname.clientID);
                    if (client == null)
                    {
                        Network.setPeer(nickname.clientID);
                        client = Network.getPeer(nickname.clientID);
                    }
                    client.nickname = nickname.nickname;
                }
                if (cmd is ClassnameCommand)
                {
                    ClassnameCommand classname = (ClassnameCommand)cmd;
                    Debug.Log("Received classname: " + classname.classname);

                    Client client = Network.getPeer(classname.clientID);
                    if (client == null)
                    {
                        Network.setPeer(classname.clientID);
                        client = Network.getPeer(classname.clientID);
                    }
                    client.classname = classname.classname;
                }
                if (cmd is UpdateClientInfoCommand)                   // called when a new player joins and needs to be synchronized
                {
                    UpdateClientInfoCommand update = (UpdateClientInfoCommand)cmd;
                    Debug.Log("Received update from client#" + update.clientID);

                    Client client = Network.getPeer(update.clientID);
                    if (client == null)
                    {
                        Network.setPeer(update.clientID);
                        client = Network.getPeer(update.clientID);
                    }
                    client.nickname  = update.nickname;
                    client.classname = update.classname;
                    client.ready     = update.ready;
                }
                if (cmd is SetSeedCommand)
                {
                    SetSeedCommand seed = (SetSeedCommand)cmd;
                    Debug.Log("Received seed!");

                    Settings.MasterSeed = seed.seed;
                }
                /*** NETWORK ACTIONS ***/
                if (cmd is JoinCommand)
                {
                    JoinCommand _join = (JoinCommand)cmd;                      // to avoid conflict with 'join' keyword
                    if (clientID == 0)
                    {
                        clientID = _join.clientID;
                        Debug.Log("Joined game! Client ID #" + clientID + " assigned!");
                    }
                    else
                    {
                        Debug.Log("New player with client ID #" + _join.clientID + " joined!");
                        Network.submitCommand(new UpdateClientInfoCommand(Network.getPeer(clientID)));
                        if (clientID == 1)
                        {
                            Network.submitCommand(new SetSeedCommand(Settings.MasterSeed));
                        }
                    }
                    Network.setPeer(_join.clientID);
                }
                if (cmd is StartCommand)
                {
                    StartCommand start = (StartCommand)cmd;
                    Debug.Log("Received START");
                    if (SceneManager.GetActiveScene().name == "NewMenu")                       // only loads new scene if we're in the lobby
                    {
                        SceneManager.LoadScene("Procedural");
                        foreach (Client client in Network.getPeers())
                        {
                            client.ready = false;
                        }
                    }
                    else
                    {
                        GameManager.NextLevel();
                    }
                }
                if (cmd is EndCommand)
                {
                    EndCommand end = (EndCommand)cmd;
                    Debug.Log("Received END");
                }
                if (cmd is DisconnectCommand)
                {
                    DisconnectCommand disconnect = (DisconnectCommand)cmd;
                    Debug.Log("Received DISCONNECT from client #" + disconnect.clientID);
                    Network.removePeer(disconnect.clientID);

                    if (clientID >= disconnect.clientID)
                    {
                        clientID--;
                        Debug.Log("Changed client ID to " + clientID);
                    }
                }
            }
        }
        if (!Network.connected())
        {
            clientID = 0;
        }
    }