Exemplo n.º 1
0
        public Action Msg(Talker talker, dynamic caller, MsgEventArgs msg)
        {
            var action = CreateMessage(talker, msg);

            caller.message(action);
            return(action);
        }
Exemplo n.º 2
0
        private void comm_IncomingMsg(object sender, EventArgs e)
        {
            if (internalState == ModuleState.Active)
            {
                MsgEventArgs msg = e as MsgEventArgs;
                switch (msg.EventCommand)
                {
                case Command.Message:
                    // agentX, agentY, agentVx, agentVy, puckX, puckY, puckVx, puckVy, puckR, oppX, oppY, oppVx, oppVy
                    string[] vals = msg.EventCommandStr.Split(',');

                    Estimate(float.Parse(vals[0]),
                             float.Parse(vals[1]),
                             float.Parse(vals[2]),
                             float.Parse(vals[3]),
                             float.Parse(vals[4]),
                             float.Parse(vals[5]),
                             float.Parse(vals[6]),
                             float.Parse(vals[7]),
                             float.Parse(vals[8]),
                             float.Parse(vals[9]),
                             float.Parse(vals[10]),
                             float.Parse(vals[11]),
                             float.Parse(vals[12])
                             );
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 3
0
 private static OpenChatAction CreateOpenChat(MsgEventArgs msg)
 {
     return(new OpenChatAction(msg.Data[1])
     {
         Title = msg.Data[2]
     });
 }
Exemplo n.º 4
0
        private void OnReceive(IAsyncResult ar)
        {
            try
            {
                clientSocket.EndReceive(ar);

                //Convert the bytes received into an object of type Data
                Data msgReceived = new Data(byteData);

                // if a msg from the server, raise incoming msg.
                if (msgReceived.sID == 0)
                {
                    if (IncomingMsg != null)
                    {
                        MsgEventArgs e = new MsgEventArgs(msgReceived.cmdCommand, msgReceived.sID, msgReceived.strMessage);
                        IncomingMsg(this, e);
                    }
                }

                byteData = new byte[1024];
                //Start listening to receive more data from the server
                clientSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref epServer,
                                              new AsyncCallback(OnReceive), null);
            }
            catch (Exception ex)
            {
                mLogger.AddLogMessage("Communicator: " + ex.Message);
                mLogger.AddLogMessage(ex.StackTrace.ToString());
            }
        }
Exemplo n.º 5
0
        public Action Msg(Talker talker, dynamic caller, MsgEventArgs msg)
        {
            var action = CreateNotice(talker.Users, msg);

            caller.notice(action);
            return(action);
        }
Exemplo n.º 6
0
 private static RegisteredAction CreateRegistered(UserManager users, MsgEventArgs msg)
 {
     return(new RegisteredAction
     {
         User = IrcUser.GetOrCreate(users, msg.Data[0] + "!@" + msg.Data[1]),
         Message = msg.Data[2]
     });
 }
Exemplo n.º 7
0
        public Action Msg(Talker talker, dynamic caller, MsgEventArgs msg)
        {
            var action = CreateNickInUse(msg);

            caller.nickInUse(action);
            talker.Send("NICK " + action.Nick + "_");
            return(action);
        }
Exemplo n.º 8
0
 private void InvokeOnLog(MsgEventArgs e)
 {
     if (OnLog == null)
     {
         return;
     }
     OnLog(this, e);
 }
Exemplo n.º 9
0
 private static NickInUseAction CreateNickInUse(MsgEventArgs msg)
 {
     return(new NickInUseAction
     {
         Nick = msg.Data[1],
         Message = msg.Data[2]
     });
 }
Exemplo n.º 10
0
 private static QuitAction CreateQuit(UserManager users, MsgEventArgs msg)
 {
     return(new QuitAction
     {
         Message = msg.Data[0],
         User = IrcUser.GetOrCreate(users, msg.Meta)
     });
 }
Exemplo n.º 11
0
 private static NoticeAction CreateNotice(UserManager users, MsgEventArgs msg)
 {
     return(new NoticeAction
     {
         Message = msg.Data[1],
         User = IrcUser.GetOrCreate(users, msg.Meta)
     });
 }
Exemplo n.º 12
0
 private static NickAction CreateNick(UserManager users, MsgEventArgs msg)
 {
     return(new NickAction
     {
         NewNick = msg.Data[0],
         User = IrcUser.GetOrCreate(users, msg.Meta)
     });
 }
Exemplo n.º 13
0
 private static ModeAction CreateMode(UserManager users, MsgEventArgs msg)
 {
     return(new ModeAction(msg.Data[0])
     {
         Mode = msg.Data[1],
         Message = msg.Data[2],
         User = IrcUser.GetOrCreate(users, msg.Meta)
     });
 }
Exemplo n.º 14
0
        public void AHMessageManager(object sender, EventArgs e)
        {
            MsgEventArgs msgE = e as MsgEventArgs;

            if (msgE.EventCommand == Command.Message)
            {
                return;
            }
            switch (msgE.EventCommand)
            {
            case Command.Start:
                // check if should update something
                mLogger.AddLogMessage("GameManager Msg: Start Msg Received with: " + msgE.EventCommandStr);
                this.AHStateManager(GameState.Playing);
                break;

            case Command.Reset:
                mLogger.AddLogMessage("GameManager Msg: Reset Msg Received with: " + msgE.EventCommandStr);
                break;

            case Command.Pause:
                mLogger.AddLogMessage("GameManager Msg: Pause Msg Received with: " + msgE.EventCommandStr);
                break;

            case Command.Score:
                // update episodes parameters
                mLogger.AddLogMessage("GameManager Msg: Score Msg Received with: " + msgE.EventCommandStr);
                string[] vals = msgE.EventCommandStr.Split(':');
                WM.UpdateScore(Convert.ToInt32(vals[0]), Convert.ToInt32(vals[1]));
                AHStateManager(GameState.GameIdle);
                break;

            case Command.Login:
                //initialize agent
                mLogger.AddLogMessage("GameManager Msg: Login Msg Received with: " + msgE.EventCommandStr);
                AHStateManager(GameState.Idle);
                break;

            case Command.NewGame:
                // initialize game
                mLogger.AddLogMessage("GameManager Msg: NewGame Msg Received with: " + msgE.EventCommandStr);
                WM.SetMaxScore(Convert.ToInt32(msgE.EventCommandStr));
                WM.UpdateScore(0, 0);
                AHStateManager(GameState.GameIdle);
                break;

            case Command.EndGame:
                // handle end of game - clear/save data
                mLogger.AddLogMessage("GameManager Msg: EndGame Msg Received with: " + msgE.EventCommandStr);
                AHStateManager(GameState.Idle);
                break;

            default:
                mLogger.AddLogMessage("GameManagerMsg: defauld Msg Received - " + msgE.EventCommand.ToString());
                break;
            }
        }
Exemplo n.º 15
0
        public void TestConnected()
        {
            var connectedHandler = new ConnectedHandler();
            var msg = new MsgEventArgs {
                Command = "001", Data = new[] { "test" }
            };

            connectedHandler.Msg(Talker, Caller, msg);
            Assert.AreEqual("test", Talker.Nick);
        }
Exemplo n.º 16
0
        public Action Msg(Talker talker, dynamic caller, MsgEventArgs msg)
        {
            var action = CreateOpenChat(msg);

            var chats = action.ChatNames.Select(talker.Chats.GetOrCreate).ToList();

            chats.ForEach(chat => chat.Title = action.Title);
            caller.openChat(action);
            return(action);
        }
Exemplo n.º 17
0
        private static PartAction CreatePart(UserManager users, MsgEventArgs msg)
        {
            var message = msg.Data.Length > 1 ? msg.Data[1] : null;

            return(new PartAction(msg.Data[0])
            {
                Message = message,
                User = IrcUser.GetOrCreate(users, msg.Meta)
            });
        }
Exemplo n.º 18
0
        public Action Msg(Talker talker, dynamic caller, MsgEventArgs msg)
        {
            var action = CreateRegistered(talker.Users, msg);

            caller.registered(action);
            talker.Nick             = action.User.Nick;
            talker.RegisteredAction = action;
            talker.OnRegisted();
            return(action);
        }
Exemplo n.º 19
0
    void cmderr(String cmd)
    {
        MsgEventArgs mea = new MsgEventArgs();

        mea.msg = "Bad command: " + cmd;
        if (EventoNuovoMessaggio != null)
        {
            EventoNuovoMessaggio(this, mea);
        }
    }
Exemplo n.º 20
0
        /// <summary>
        /// Manage incoming messages
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Cm_MessageEvent(object sender, MsgEventArgs e)
        {
            if (e.DataType == typeof(string))
            {
                bool    received = true;
                Message decoded  = Message.FromJson(e.Data as string);
                if (decoded.Sender == (sender as CommunicationModule).Id)
                {
                    received = false;
                }
                // we received a non decryptable message
                if (decoded.Kind == MessageKindType.VOID)
                {
                    return;
                }
                string displayName;
                this.Dispatcher.Invoke(() =>
                {
                    if (sender == userModule)
                    {
                        if (decoded.Kind == MessageKindType.USER)
                        {
                            if (Book.Add(decoded.Sender, (decoded as ChatUser)) &&
                                (decoded as ChatUser).Sender != UserProfile.Sender)
                            {
                                HelloMessage(decoded as ChatUser);
                            }
                        }
                    }
                    else
                    {
                        ChatUser cu     = Book.RetrieveUser(decoded.Sender);
                        displayName     = (cu != null) ? cu.Name + " " + cu.LastName : decoded.Sender.GetHashCode().ToString();
                        string verified = (decoded.Verified) ? "V+" : "!?";

                        if (received)
                        {
                            TextArea += string.Format("{0} {1}-{2}>> {3}{4}", verified, e.Timestamp.ToShortTimeString(), displayName, decoded.StringContent, Environment.NewLine);
                        }
                        else
                        {
                            TextArea += string.Format("{0} {1}-{2}-- {3}{4}", verified, e.Timestamp.ToShortTimeString(), displayName, decoded.StringContent, Environment.NewLine);
                        }
                        if (cu == null)
                        {
                            cu = new ChatUser()
                            {
                                Name = decoded.Sender.GetHashCode().ToString(), LastName = string.Empty
                            };
                        }
                        MessageList.Add(decoded, cu, received);
                    }
                });
            }
        }
Exemplo n.º 21
0
        private void saveData(object sender, MsgEventArgs args)
        {
            Console.WriteLine(string.Format("我是:{1},收到{2}的消息,内容是:{0},saveData", args.Data, "Module3", args.EventType));

            CustomArgs p1 = args as CustomArgs;

            if (p1 != null)
            {
                Console.WriteLine("子类参数对象获取成功!");
            }
        }
Exemplo n.º 22
0
 public Action Msg(Talker talker, dynamic caller, MsgEventArgs msg)
 {
     caller.msg(new
     {
         type    = msg.Type,
         command = msg.Command,
         meta    = msg.Meta,
         data    = msg.Data
     });
     return(null);
 }
Exemplo n.º 23
0
        public Action Msg(Talker talker, dynamic caller, MsgEventArgs msg)
        {
            var action = CreateQuit(talker.Users, msg);

            caller.quit(action);
            var chats = talker.Chats.Where(c => c.Users.Any(u => u.IrcUser.Nick == action.User.Nick)).ToList();

            chats.ForEach(chat => chat.Users.RemoveWhere(u => u.IrcUser.Nick == action.User.Nick));
            chats.ForEach(chat => action.ChatNames.Add(chat.Name));
            return(action);
        }
Exemplo n.º 24
0
        public void TestNamesAddedToChannelNames()
        {
            var namesListHandler = new NamesListHandler();
            var msg = new MsgEventArgs {
                Command = "353", Data = new[] { "", "", "test", "hello world" }
            };

            Caller.namesList = new Action <NamesListAction>(r => { });
            namesListHandler.Msg(Talker, Caller, msg);
            //CollectionAssert.AreEqual(new[] {"hello", "world"}, Talker.GetChat("test").Users.ToArray());
        }
Exemplo n.º 25
0
        public void TestPartRemoveName()
        {
            var partHandler = new PartHandler();
            var msg         = new MsgEventArgs {
                Command = "PART", Data = new[] { "test", "Hello, world!" }, Meta = "a!b@c"
            };

            Caller.part = new Action <PartAction>(res => { });
            AddChatUsers("test", "a", "b", "c");
            partHandler.Msg(Talker, Caller, msg);
            CollectionAssert.AreEqual(new[] { "b", "c" }, Talker.Chats["test"].Users.Select(u => u.IrcUser.Nick).ToArray());
        }
Exemplo n.º 26
0
        public void TestPartWithoutMessage()
        {
            var partHandler = new PartHandler();
            var msg         = new MsgEventArgs {
                Command = "PART", Data = new[] { "test" }, Meta = "a!b@c"
            };
            var visited = false;

            Caller.part = new Action <PartAction>(res => { visited = true; });
            partHandler.Msg(Talker, Caller, msg);
            Assert.IsTrue(visited);
        }
Exemplo n.º 27
0
        public void TestMessage()
        {
            var messageHandler = new MessageHandler();
            var msg            = new MsgEventArgs {
                Command = "PRIVMSG", Data = new[] { "test", "Hello, world!" }, Meta = "a!b@c"
            };
            var visited = false;

            Caller.message = new Action <MessageAction>(res => { visited = true; });
            messageHandler.Msg(Talker, Caller, msg);
            Assert.IsTrue(visited);
        }
Exemplo n.º 28
0
        public void TestSelfNickNoChangeIfNotSame()
        {
            var nickHandler = new NickHandler();

            Talker.Nick = "b";
            var msg = new MsgEventArgs {
                Command = "nick", Data = new[] { "test" }, Meta = "a!b@c"
            };

            Caller.nick = new Action <NickAction>(res => { });
            nickHandler.Msg(Talker, Caller, msg);
            Assert.AreEqual("b", Talker.Nick);
        }
Exemplo n.º 29
0
        public void TestHasRegisteredHandlerInTalker()
        {
            var registeredHandler = new RegisteredHandler();
            var msg = new MsgEventArgs {
                Command = "396", Data = new[] { "hello_", "world", "oh, hai :)" }
            };
            RegisteredAction action = null;

            Caller.registered = new Action <RegisteredAction>(res => { action = res; });
            Assert.IsNull(Talker.RegisteredAction);
            registeredHandler.Msg(Talker, Caller, msg);
            Assert.IsNotNull(Talker.RegisteredAction);
            Assert.AreEqual(action, Talker.RegisteredAction);
        }
Exemplo n.º 30
0
        public void TestJoinAddName()
        {
            AddChatUsers("test", "a", "b", "c");

            Caller.join = new Action <JoinAction>(res => { });
            var joinHandler = new JoinHandler();
            var msg         = new MsgEventArgs {
                Command = "JOIN", Data = new[] { "test" }, Meta = "d!b@c"
            };

            joinHandler.Msg(Talker, Caller, msg);
            CollectionAssert.AreEqual(new[] { "a", "b", "c", "d" },
                                      Talker.Chats["test"].Users.Select(u => u.IrcUser.Nick).ToArray());
        }
Exemplo n.º 31
0
 private void InfoMsg(object sender, MsgEventArgs e)
 {
     Info(e.Message);
 }
Exemplo n.º 32
0
 protected virtual void OnNewMessage(MsgEventArgs args)
 {
     if (!_bHandleEvents)
         return;
     System.Diagnostics.Debug.WriteLine("OnNewMessage: " + args.msg);
     NewMessageEventHandler handler = newMsgEvent;
     if (handler != null)
     {
         handler(this, args);
     }
 }
Exemplo n.º 33
0
 private void LogMsg(object sender, MsgEventArgs e)
 {
     Log(e.Message);
 }