예제 #1
0
 public static void tBlazeMain(object obj)
 {
     try
     {
         Log("[MAIN] Blaze starting...");
         Profiles.Refresh();
         lBlaze = new TcpListener(IPAddress.Parse(ProviderInfo.backendIP), 30001);
         Log("[MAIN] Blaze bound to " + ProviderInfo.backendIP + ":30001");
         lBlaze.Start();
         Log("[MAIN] Blaze listening...");
         while (!GetExit())
         {
             while (!BlazeServer.GetExit())
             {
                 new Thread(new ParameterizedThreadStart(tBlazeClientHandler)).Start((object)lBlaze.AcceptTcpClient());
             }
         }
     }
     catch (Exception ex)
     {
         LogError("MAIN", ex);
     }
 }
예제 #2
0
 public static void RefreshProfiles()
 {
     Profiles.Refresh();
 }
예제 #3
0
        public static void ProcessMagma(string data, Stream s)
        {
            string[] lines = data.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            Log("[MGMA] Request: " + lines[0]);
            string cmd = lines[0].Split(' ')[0];
            string url = lines[0].Split(' ')[1].Split(':')[0];

            if (cmd == "GET")
            {
                switch (url)
                {
                case "/api/nucleus/authToken":
                    Log("[MGMA] Sending AuthToken");
                    if (lines.Length > 5 && lines[5].StartsWith("x-server-key"))
                    {
                        ReplyWithXML(s, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<success><token>" + lines[5].Split(':')[1].Trim() + "</token></success>");
                    }
                    else
                    {
                        ReplyWithXML(s, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<success><token code=\"NEW_TOKEN\">" + lines[4].Split('=')[1] + "</token></success>");
                    }
                    return;

                case "/api/relationships/roster/nucleus":
                    Log("[MGMA] Sending Roster response");
                    ReplyWithXML(s, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<roster relationships=\"0\"/><success code=\"SUCCESS\"/>");
                    return;

                case "/wv/getProfiles":
                    Log("[MGMA] Sending Player Profiles");
                    StringBuilder sb = new StringBuilder();
                    Profiles.Refresh();
                    sb.Append("<profiles>\r\n");
                    foreach (Profile p in Profiles.profiles)
                    {
                        sb.Append("<profile name='" + Profiles.getProfilePath(p.id) + "'>" + Convert.ToBase64String(Encoding.Unicode.GetBytes(p._raw)) + "</profile>\r\n");
                    }
                    sb.Append("</profiles>\r\n");
                    ReplyWithXML(s, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n" + sb.ToString());
                    break;
                }
                if (url.StartsWith("/api/nucleus/name/"))
                {
                    int id = Convert.ToInt32(url.Substring(18));
                    Log("[MGMA] Sending name response for PID " + id);
                    PlayerInfo p = null;
                    foreach (PlayerInfo pi in BlazeServer.allClients)
                    {
                        if (pi.userId == id)
                        {
                            p = pi;
                            break;
                        }
                    }
                    if (p == null)
                    {
                        Log("[MGMA] Cant find player id!");
                        return;
                    }
                    ReplyWithXML(s, "<name>" + p.profile.name + "</name>");
                }
                if (url.StartsWith("/api/nucleus/entitlements/"))
                {
                    int id = Convert.ToInt32(url.Substring(26));
                    Log("[MGMA] Sending entitlement response for PID " + id);
                    PlayerInfo p = null;
                    foreach (PlayerInfo pi in BlazeServer.allClients)
                    {
                        if (pi.userId == id)
                        {
                            p = pi;
                            break;
                        }
                    }
                    if (p == null)
                    {
                        Log("[MGMA] Cant find player id!");
                        return;
                    }
                    string response = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><entitlements count=\"" + entitlements.Count + "\">";
                    int    i        = 1;
                    foreach (KeyValuePair <int, int> pair in entitlements)
                    {
                        response += "<entitlement><entitlementId>"
                                    + Convert.ToString(i)
                                    + "</entitlementId><entitlementTag>"
                                    + pair.Key
                                    + "-UNLM-</entitlementTag><useCount>" + pair.Value + "</useCount><grantDate>"
                                    + DateTime.UtcNow.ToString("MMM-dd-yyyy HH:mm:ss UTC")
                                    + "</grantDate><terminationDate></terminationDate><status>ACTIVE</status></entitlement>";
                        i++;
                    }
                    response += "</entitlements>";
                    ReplyWithXML(s, response);
                }
            }
            if (cmd == "POST" && !basicMode)
            {
                int pos = data.IndexOf("\r\n\r\n");
                if (pos != -1)
                {
                    Log("[MGMA] Content: \n" + data.Substring(pos + 4));
                }
            }
        }