Example #1
0
        public void SetPlayerInfo(PlayerInfo info)
        {
            GameState.Instance.SetPlayerInfo(info);
            ClientHandler.Instance.SetHandler(new IngameMessageHandler());

            SRActionMessage msg = new SRActionMessage(ActionType.GetMapData, ServiceType.Map);
            msg.args[ArgumentName.PlayerId] = info.id;
            ClientHandler.Instance.SendMessage(msg);
        }
Example #2
0
 void SendLogin()
 {
     SRActionMessage msg = new SRActionMessage(ActionType.DoLogin, ServiceType.Login);
     msg.args = new Dictionary<ArgumentName, object>()
     {
         { ArgumentName.LoginUsername, "stryfe" },
         { ArgumentName.LoginPassword, "123" }
     };
     ClientHandler.Instance.SendMessage(msg);
 }
Example #3
0
        public void Run()
        {
            // Client initialization
            config = new NetPeerConfiguration("stryferpg");
            client = new NetClient(config);
            client.Start();
            client.Connect("localhost", 1234);

            handler = new LoginMessageHandler();

            // Messages receipt
            NetIncomingMessage message;
            while (!stop)
            {
                while ((message = client.ReadMessage()) != null)
                {
                    switch (message.MessageType)
                    {
                        case NetIncomingMessageType.Data:
                            SROrderMessage msg = NetworkSerializer.DeserializeObject<SROrderMessage>(message.ReadBytes(message.LengthBytes));
                            handler.Handle(msg);
                            break;

                        case NetIncomingMessageType.StatusChanged:
                            switch (message.SenderConnection.Status)
                            {
                                case NetConnectionStatus.Connected:
                                    Console.WriteLine("Connected");
                                    Console.WriteLine("Asking for server list...");

                                    SRActionMessage action = new SRActionMessage(ActionType.GetServerList, ServiceType.Login);
                                    SendMessage(action);
                                    break;
                            }

                            break;

                        case NetIncomingMessageType.DebugMessage:
                            Console.WriteLine(message.ReadString());
                            break;

                        default:
                            Console.WriteLine("unhandled message with type: "
                                + message.MessageType);
                            break;
                    }
                }
                
                Thread.Sleep(1);
            }
        }
Example #4
0
 public void Handle(SRActionMessage msg, NetConnection conn)
 {
     switch (msg.type)
     {
         case ActionType.GetMapData:
             SendMapData((int)msg.args[ArgumentName.PlayerId], conn);
             break;
         case ActionType.UpdatePosition:
             UpdatePlayerPosition(msg.args, conn);
             break;
         default:
             break;
     }
 }
        public void Send(ActionType type, Dictionary<ArgumentName, object> args)
        {
            SRActionMessage msg = null;
            switch (type)
            {
                case ActionType.UpdatePosition:
                    msg = new SRActionMessage(type, ServiceType.Map);
                    msg.args = args;
                    break;
            }

            if (msg != null)
                ClientHandler.Instance.SendMessage(msg);
        }
        void UpdateMapInfo(Dictionary<ArgumentName, object> info)
        {
            // Sets players around
            Stryfe.Instance.ChangeScene(Scene.SceneType.Game);
            MapManager.Instance.UpdatePlayers(info[ArgumentName.VisiblePlayers] as List<PlayerInfo>);

            // Updates itself for other players
            SRActionMessage msg = new SRActionMessage(ActionType.UpdatePosition, ServiceType.Map);
            msg.args[ArgumentName.PlayerInfo] = GameState.Instance.playerInfo;
            ClientHandler.Instance.SendMessage(msg);

            // Sets NPCs around

            // Sets enemies around
        }
Example #7
0
 public void Handle(SRActionMessage msg, NetConnection conn)
 {
     switch (msg.type)
     {
         case ActionType.DoLogin:
             if (msg.args.ContainsKey(ArgumentName.LoginUsername) &&
                 msg.args.ContainsKey(ArgumentName.LoginPassword))
             {
                 DoLogin(msg.args[ArgumentName.LoginUsername] as string,
                         msg.args[ArgumentName.LoginPassword] as string,
                         conn);
             }
             break;
         case ActionType.GetServerList:
             SendServerList(conn);
             break;
         default:
             break;
     }
 }
Example #8
0
 public void SendMessage(SRActionMessage action)
 {
     NetOutgoingMessage msg = client.CreateMessage();
     msg.Write(NetworkSerializer.SerializeObject(action));
     client.SendMessage(msg, NetDeliveryMethod.ReliableOrdered);
 }