private void appServer_NewSessionConnected(GameWebsocketSession session)
        {
            //@TODO collision objects shouldn't be sent!


            //send all others who you are first

            foreach (GameWebsocketSession session2 in appServer.GetAllSessions())
            {
                if (session == session2)
                {
                    continue;
                }

                session2.Send(Newtonsoft.Json.JsonConvert.SerializeObject(GameObjectFactory.to(TheGame.Instance.gameObjects.getIdFor(session.Player), session.Player)));
            }


            //sync all the objects
            foreach (KeyValuePair <int, GameObject> keyValuePair in TheGame.Instance.gameObjects)
            {
                session.Send(Newtonsoft.Json.JsonConvert.SerializeObject(GameObjectFactory.to(keyValuePair.Key, keyValuePair.Value)));
            }

            //let him now which one is him
            session.Send(Newtonsoft.Json.JsonConvert.SerializeObject(
                             new WhatDoWeDoNow.JSON.GameObjectYouAre {
                Id = TheGame.Instance.gameObjects.getIdFor(session.Player)
            }
                             ));
        }
        private void syncPlayerPosition(GameWebsocketSession session)
        {
            if (session.Player.lastPositionTransmitted == session.Player.getPos())
            {
                return;
            }

            string toSend = TheGame.Instance.makeGameobjectPositionChangeFromGameObject(session.Player);

            foreach (GameWebsocketSession session2 in appServer.GetAllSessions())
            {
                session2.Send(toSend);
            }

            session.Player.lastPositionTransmitted = session.Player.getPos();
        }
        private void appServer_NewMessageReceived(GameWebsocketSession session, string value)
        {
            dynamic d = JObject.Parse(value);

            Console.WriteLine("Received #" + messagesReceived + " received and type is: " + d.Type);
            ++messagesReceived;

            if (d.Type == (new WhatDoWeDoNow.JSON.GameObjectPositionChange()).Type)
            {
                WhatDoWeDoNow.JSON.GameObjectPositionChange obj = JsonConvert.DeserializeObject <WhatDoWeDoNow.JSON.GameObjectPositionChange>(value);

                foreach (GameWebsocketSession session2 in appServer.GetAllSessions())
                {
                    if (session == session2)
                    {
                        continue;
                    }

                    session2.Send(value);
                }
            }
            if (d.Type == (new WhatDoWeDoNow.JSON.PlayerChange("bla")).Type)
            {
                WhatDoWeDoNow.JSON.PlayerChange obj = JsonConvert.DeserializeObject <WhatDoWeDoNow.JSON.PlayerChange>(value);

                //apply it on user
                if (obj.Change == "Down")
                {
                    session.Player.playerDownCommand();
                }
                if (obj.Change == "DownEnd")
                {
                    session.Player.playerDownCommandEnd();
                }
                if (obj.Change == "Up")
                {
                    session.Player.playerUpCommand();
                }
                if (obj.Change == "UpEnd")
                {
                    session.Player.playerUpCommandEnd();
                }
                if (obj.Change == "Left")
                {
                    session.Player.playerLeftCommand();
                }
                if (obj.Change == "LeftEnd")
                {
                    session.Player.playerLeftCommandEnd();
                }
                if (obj.Change == "Right")
                {
                    session.Player.playerRightCommand();
                }
                if (obj.Change == "RightEnd")
                {
                    session.Player.playerRightCommandEnd();
                }
                if (obj.Change == "Jump")
                {
                    session.Player.playerJumpCommand();
                }
                if (obj.Change == "JumpEnd")
                {
                    session.Player.playerJumpCommandEnd();
                }
            }
        }