コード例 #1
0
    public void Send(params object[] p)
    {
        if (!GameConfig.MpEnabled)
        {
            return;
        }

        string msg = "";

        foreach (object o in p)
        {
            if (msg.Length > 0)
            {
                msg += " ";
            }
            msg += o.ToString();
        }
        if (!msg.EndsWith("\n"))
        {
            msg += "\n";
        }
        byte[] encoded = Encoding.ASCII.GetBytes(msg);
        try {
            Stream.Write(encoded, 0, encoded.Length);
            Stream.Flush();
        } catch (System.IO.IOException) {
            Restart();
        }
        catch (Exception ex) {
            MpUtils.Log(MpUtils.LogLevel.Error, "MpClient",
                        "Unhandled exception in MpClient.Send of type {0}: {1}",
                        ex.GetType().Name, ex.Message);
        }
    }
コード例 #2
0
        public void PurchaseProduct(string productId)
        {
            try
            {
                // In case we need to process a delayed payment, otherwise our HandleActivityResult below will handle
                MpUtils.EnablePaymentBroadcast(Android.App.Application.Context, "com.simsip.permission.PAYMENT_BROADCAST_PERMISSION");

                PaymentRequest.PaymentRequestBuilder builder = new PaymentRequest.PaymentRequestBuilder();

                builder.SetService(FortumoInAppService._serviceId, FortumoInAppService._inAppSecret);

                // TODO
                var practiceText = string.Empty;
                builder.SetDisplayString(practiceText);

                // Non-consumable purchases are restored using this value
                builder.SetProductName(FortumoInAppService._productName);

                // Non-consumable items can be later restored
                builder.SetType(MpUtils.ProductTypeNonConsumable);

                builder.SetIcon(Resource.Drawable.icon);

                PaymentRequest pr = builder.Build();

                // Can be anything
                int REQUEST_CODE = 1234;

                MainActivity.Instance.StartActivityForResult(pr.ToIntent(Android.App.Application.Context), REQUEST_CODE);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception in PurchaseProduct: " + ex);
            }
        }
コード例 #3
0
ファイル: MpHandler.cs プロジェクト: jtuttle/haven
 private void SomeoneDropped(string cid)
 {
     if (OtherPlayers.ContainsKey(cid))
     {
         DelegateWork(() => {
             if (OtherPlayers.ContainsKey(cid))
             {
                 OtherPlayer op = OtherPlayers[cid];
                 GameObject.Destroy(op.Actor);
                 OtherPlayers.Remove(cid);
                 MpUtils.Log(MpUtils.LogLevel.Info, "MpHandler",
                             "Someone dropped out, was {0}, now {1} other players",
                             cid, OtherPlayers.Count);
             }
         });
     }
 }
コード例 #4
0
ファイル: MpHandler.cs プロジェクト: jtuttle/haven
 private void SomeoneJoined(string cid)
 {
     if (!OtherPlayers.ContainsKey(cid))
     {
         DelegateWork(() => {
             if (!OtherPlayers.ContainsKey(cid))
             {
                 OtherPlayer op    = new OtherPlayer(cid);
                 OtherPlayers[cid] = op;
                 op.Actor          = UnityUtils.LoadResource <GameObject>("Prefabs/OtherPlayer", true);
                 MpUtils.Log(MpUtils.LogLevel.Info, "MpHandler",
                             "Someone joined {0}, now {1} other players",
                             cid, OtherPlayers.Count);
             }
         });
     }
 }
コード例 #5
0
    private void ReadSync()
    {
        string accum = "";

        byte[] buff = new byte[512];

        MpUtils.Log(MpUtils.LogLevel.Warning, "MpClient", "Now reading from connection");
        while (ContinueRunning)
        {
            try
            {
                IAsyncResult ar = Stream.BeginRead(buff, 0, buff.Length, null, null);
                while (!ar.IsCompleted && ContinueRunning)
                {
                    Thread.Sleep(200);
                }
                if (!ContinueRunning)
                {
                    return;
                }
                int    read    = Stream.EndRead(ar);
                string decoded = Encoding.ASCII.GetString(buff, 0, read);
                accum += decoded;
                while (accum.Contains("\n"))
                {
                    string nextLine = accum.Substring(0, accum.IndexOf("\n"));
                    accum = accum.Substring(accum.IndexOf("\n") + 1);
                    ParseAndDoleOut(nextLine);
                }
            }
            catch (System.IO.IOException)
            {
                MpUtils.Log(MpUtils.LogLevel.Warning, "MpClient", "Connection broken, no longer reading");
                ContinueRunning = false;
            }
            catch (Exception ex)
            {
                MpUtils.Log(MpUtils.LogLevel.Error, "MpClient",
                            "Unhandled exception in MpClient.ReadSync of type {0}: {1}",
                            ex.GetType().Name, ex.Message);
                ContinueRunning = false;
            }
        }
    }
コード例 #6
0
    private void ParseAndDoleOut(string feed)
    {
        List <string> feedParts = new List <string>(feed.Split(new char[] { ' ' }));

        if (feedParts.Count == 0)
        {
            return;
        }
        feedParts.Reverse();
        Stack <string> parts = new Stack <string>(feedParts);

        string cid = parts.Pop();

        if (cid == "identity")
        {
            Identity = parts.Pop();
            MpUtils.Log(MpUtils.LogLevel.Info, "MpClient",
                        "[MpClient] Now identity {0}", Identity);
        }
        else if (cid == "error")
        {
            MpUtils.Log(MpUtils.LogLevel.Warning, "MpClient",
                        "[MpClient] Server sent error: {0}", feed);
        }
        else if (cid == Identity)
        {
            /* ignore stuff about us, we already know yo */
        }
        else
        {
            string cmd = parts.Pop();
            if (cmd == "position")
            {
                if (OnPositionUpdate != null)
                {
                    float px = float.Parse(parts.Pop());
                    float py = float.Parse(parts.Pop());
                    float pz = float.Parse(parts.Pop());
                    OnPositionUpdate(cid, px, py, pz);
                }
            }
            else if (cmd == "join")
            {
                if (OnSomeoneJoined != null)
                {
                    OnSomeoneJoined(cid);
                }
            }
            else if (cmd == "drop")
            {
                if (OnSomeoneDropped != null)
                {
                    OnSomeoneDropped(cid);
                }
            }
            else
            {
                MpUtils.Log(MpUtils.LogLevel.Error, "MpClient",
                            "No handler for cmd {0} on cid {1}", cmd, cid);
            }
        }
    }