Beispiel #1
0
        string ProcessYamlStream(string file, bool cdKey)
        {
            string info = file + Environment.NewLine;

            try
            {
                var data  = File.ReadAllText(file);
                var plist = data.Split(new[] { "peer" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var pd in plist)
                {
                    if (pd[0] == '#')
                    {
                        continue;
                    }
                    var dir      = pd[0] == '0' ? "GAM " : "SRV ";
                    var b64Data  = pd.Split('|')[1].Split('#')[0].Trim().Replace("\n", "");
                    var peerData = Convert.FromBase64String(b64Data);
                    try
                    {
                        if (cdKey)
                        {
                            var msg = new CDKeyMessage(peerData);
                            info += dir + msg.ToString() + Environment.NewLine;
                        }
                        else
                        {
                            var msgList = S5GameServices.Message.ParseIncoming(peerData);

                            foreach (var msg in msgList)
                            {
                                info += dir + msg.ToString() + Environment.NewLine;
                            }
                        }
                    }
                    catch (Exception ex) { info += dir + "!! EXECPTION: " + ex.Message + Environment.NewLine; }
                }
            }
            catch (Exception e)
            {
                info += e.ToString();
            }

            return(info);
        }
Beispiel #2
0
        async static void HandlePacket(IAsyncResult ar)
        {
            var udpClient      = ar.AsyncState as UdpClient;
            var remoteEndpoint = new IPEndPoint(IPAddress.Any, 0);
            var reqData        = udpClient.EndReceive(ar, ref remoteEndpoint);

            udpClient.BeginReceive(HandlePacket, udpClient);

            var req         = new CDKeyMessage(reqData);
            var endpointDbg = remoteEndpoint.ToString().PadRight(22);

            logger.WriteDebug("CDKeyServer           {0}GAM: {1}", endpointDbg, req.Data.ToString());

            CDKeyMessage response;
            int          clientID;

            byte[] token;
            switch (req.Data[1].AsInt)
            {
            case 1: response = getTokenResponse; break;

            case 2:
                response = authorizeResponse;
                clientID = rng.Next(int.MinValue, int.MaxValue);
                token    = ToToken(clientID, 16);
                response.Data[3][1][0].AsBinary = token;
                response.Data[3][1][1].AsBinary = token;
                break;

            case 3:
                response = login1Response;
                clientID = ToID(req.Data[3][0].AsBinary);
                response.Data[3][1][0].AsBinary = ToToken(clientID, 20);
                await Task.Delay(300);     //crazy racecondition in S5: the host needs to have set up his XNetwork before the clients send their AuthTokens to verify,

                break;

            case 4:
                response = login2Response;
                clientID = ToID(req.Data[3][0].AsBinary);
                response.Data[3][1][1].AsBinary = ToToken(clientID, 16);
                break;

            case 6: response = logoutResponse; break;

            case 7: return;     //heartbeat

            default:

                logger.WriteError("CDKeyServer           {0}Unknown CDKey request: {1}", endpointDbg, req.Data.ToString());
                return;
            }

            var udpConnId = req.Data[0].AsString;

            response.Data[0].AsString = udpConnId;
            logger.WriteDebug("CDKeyServer           {0}SRV: {1}", endpointDbg, response.Data.ToString());

            var respData = response.Serialize();
            await udpClient.SendAsync(respData, respData.Length, remoteEndpoint);
        }