Exemplo n.º 1
0
    private void ClientConnected(uint playerID, Vector2 playerPos)
    {
        DataCollectionPackage package = new DataCollectionPackage();
        PositionDataPackage   pData   = new PositionDataPackage()
        {
            PlayerName = clientName,
            PlayerID   = playerID,
            Position   = playerPos
        };

        package.PositionDataPackages.Add(pData);

        //Første package er mappens dimensioner
        GridDataPackage gData = new GridDataPackage()
        {
            X = Server.MapGrid.gridWidth,
            Y = Server.MapGrid.gridHeigth
        };

        package.GridDataPackages.Add(gData);


        MessageType msgType     = MessageType.Connect;
        string      jsonPackage = JsonUtility.ToJson(package);
        string      msg         = ((int)msgType).ToString();

        msg += Server.MESSAGE_TYPE_INDICATOR + jsonPackage;
        byte[] byteData = System.Text.Encoding.ASCII.GetBytes(msg);

        byte[] totalPackage = Server.AddSizeHeaderToPackage(byteData);

        SendToClient(totalPackage);

        try
        {
            UserSession ses = new UserSession()
            {
                UserID = clientName, InGame = true, Request = SessionRequest.SetStatus
            };
            byte[] data = TCPHelper.MessageBytes(ses);
            Server.SessionClient.GetStream().Write(data, 0, data.Length);
        }
        catch
        {
        }
    }
Exemplo n.º 2
0
    private void ClientConnected(uint playerID, Vector2 playerPos)
    {
        PositionDataPackage package = new PositionDataPackage()
        {
            PlayerID = playerID,
            Position = playerPos
        };
        MessageType msgType     = MessageType.Connect;
        string      jsonPackage = JsonUtility.ToJson(package);
        string      msg         = ((int)msgType).ToString();

        msg += HeadlessServer.MESSAGE_TYPE_INDICATOR + jsonPackage;
        byte [] byteData = System.Text.Encoding.ASCII.GetBytes(msg);

        byte [] totalPackage = HeadlessServer.AddSizeHeaderToPackage(byteData);

        SendToClient(totalPackage);
    }