Ejemplo n.º 1
0
    private void OnSetPlayer_PrePass(ServerRequestBase r)
    {
        SetPlayerRequest request = (SetPlayerRequest)r;

        NetworkManager.Instance.SuccessMatched();
        InitializePlayers(request);
    }
Ejemplo n.º 2
0
    public override void Deserialize(DataStream reader)
    {
        base.Deserialize(reader);
        int attachedRequestsCount = reader.ReadSInt32();

        for (int i = 0; i < attachedRequestsCount; i++)
        {
            ServerRequestBase request = (ServerRequestBase)ProtoManager.TryDeserialize(reader, null);
            AttachedRequests.Add(request);
        }
    }
Ejemplo n.º 3
0
 private void sendMessage(ServerRequestBase request)
 {
     if (request is ResponseBundleBase r)
     {
         foreach (ServerRequestBase req in r.AttachedRequests)
         {
             if (req is PlayerTurnRequest ptr) // Only listen to round start
             {
                 if (ptr.clientId == ClientID)
                 {
                     AIOperation();
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
 protected virtual void SendMessage(ServerRequestBase request)
 {
     if (isClosed)
     {
         return;
     }
     SendRequestsQueue.Enqueue(request);
     if (SendRequestsQueue.Count > 0)
     {
         try
         {
             SendMsg msg = new SendMsg(Socket, SendRequestsQueue.Dequeue(), ClientID);
             Server.SV.DoSendToClient(msg);
         }
         catch (Exception e)
         {
             Console.WriteLine(e);
         }
     }
 }
Ejemplo n.º 5
0
    public void ResponseToSideEffects_PrePass(ServerRequestBase r) //第一轮
    {
        switch (r.GetProtocol())
        {
        case NetProtocols.SE_SET_PLAYER:
        {
            Client.Instance.Proxy.ClientState = ProxyBase.ClientStates.Playing;
            OnSetPlayer_PrePass(r);
            break;
        }

        case NetProtocols.SE_BATTLEGROUND_ADD_MECH:
        {
            OnBattleGroundAddMech_PrePass((BattleGroundAddMechRequest)r);
            break;
        }

        case NetProtocols.SE_BATTLEGROUND_REMOVE_MECH:
        {
            OnBattleGroundRemoveMech_PrePass((BattleGroundRemoveMechRequest)r);
            break;
        }
        }
    }
Ejemplo n.º 6
0
    public void ResponseToSideEffects(ServerRequestBase r)
    {
        switch (r.GetProtocol())
        {
        case NetProtocols.SE_PLAYER_TURN:
        {
            OnSetPlayerTurn((PlayerTurnRequest)r);
            break;
        }

        case NetProtocols.SE_PLAYER_METAL_CHANGE:
        {
            OnSetPlayersMetal((PlayerMetalChangeRequest)r);
            break;
        }

        case NetProtocols.SE_PLAYER_LIFE_CHANGE:
        {
            OnSetPlayersLife((PlayerLifeChangeRequest)r);
            break;
        }

        case NetProtocols.SE_PLAYER_ENERGY_CHANGE:
        {
            OnSetPlayersEnergy((PlayerEnergyChangeRequest)r);
            break;
        }

        case NetProtocols.SE_MECH_ATTRIBUTES_CHANGE:
        {
            OnMechAttributesChange((MechAttributesChangeRequest)r);
            break;
        }

        case NetProtocols.SE_MECH_DIE:
        {
            OnMechDie((MechDieRequest)r);
            break;
        }

        case NetProtocols.SE_BATTLEGROUND_ADD_MECH:
        {
            OnBattleGroundAddMech((BattleGroundAddMechRequest)r);
            break;
        }

        case NetProtocols.SE_BATTLEGROUND_REMOVE_MECH:
        {
            OnBattleGroundRemoveMech((BattleGroundRemoveMechRequest)r);
            break;
        }

        case NetProtocols.SE_PLAYER_BUFF_UPDATE_REQUEST:
        {
            OnUpdatePlayerBuff((PlayerBuffUpdateRequest)r);
            break;
        }

        case NetProtocols.SE_PLAYER_COOLDOWNCARD_UPDATE_REQUEST:
        {
            OnUpdatePlayerCoolDownCard((PlayerCoolDownCardUpdateRequest)r);
            break;
        }

        case NetProtocols.SE_PLAYER_COOLDOWNCARD_REMOVE_REQUEST:
        {
            OnRemovePlayerCoolDownCard((PlayerCoolDownCardRemoveRequest)r);
            break;
        }

        case NetProtocols.SE_CARDDECT_LEFT_CHANGE:
        {
            OnCardDeckLeftChange((CardDeckLeftChangeRequest)r);
            break;
        }

        case NetProtocols.SE_DRAW_CARD:
        {
            OnPlayerDrawCard((DrawCardRequest)r);
            break;
        }

        case NetProtocols.SE_DROP_CARD:
        {
            OnPlayerDropCard((DropCardRequest)r);
            break;
        }

        case NetProtocols.SE_USE_CARD:
        {
            OnPlayerUseCard((UseCardRequest)r);
            break;
        }

        case NetProtocols.SE_MECH_CARDINFO_SYNC:
        {
            OnMechCardInfoSync((MechCardInfoSyncRequest)r);
            break;
        }

        case NetProtocols.SE_EQUIP_WEAPON_SERVER_REQUEST:
        {
            OnEquipWeapon((EquipWeaponServerRequest)r);
            break;
        }

        case NetProtocols.SE_EQUIP_SHIELD_SERVER_REQUEST:
        {
            OnEquipShield((EquipShieldServerRequest)r);
            break;
        }

        case NetProtocols.SE_EQUIP_PACK_SERVER_REQUEST:
        {
            OnEquipPack((EquipPackServerRequest)r);
            break;
        }

        case NetProtocols.SE_EQUIP_MA_SERVER_REQUEST:
        {
            OnEquipMA((EquipMAServerRequest)r);
            break;
        }

        case NetProtocols.SE_USE_SPELLCARD_SERVER_REQUEST:
        {
            OnUseSpellCard((UseSpellCardServerRequest)r);
            break;
        }

        case NetProtocols.SE_MECH_ATTACK_MECH_SERVER_REQUEST:
        {
            OnMechAttackMech((MechAttackMechServerRequest)r);
            break;
        }

        case NetProtocols.SE_MECH_ATTACK_SHIP_SERVER_REQUEST:
        {
            OnMechAttackShip((MechAttackShipServerRequest)r);
            break;
        }

        case NetProtocols.SE_MECH_CANATTACK:
        {
            OnMechCanAttackChange((MechCanAttackRequest)r);
            break;
        }

        case NetProtocols.SE_MECH_IMMUNE:
        {
            OnMechImmuneChange((MechImmuneStateRequest)r);
            break;
        }

        case NetProtocols.SE_MECH_INACTIVITY:
        {
            OnMechInactivityChange((MechInactivityStateRequest)r);
            break;
        }

        case NetProtocols.SE_MECH_ONATTACK:
        {
            OnMechOnAttack((MechOnAttackRequest)r);
            break;
        }

        case NetProtocols.SE_MECH_ONATTACKSHIP:
        {
            OnMechOnAttackShip((MechOnAttackShipRequest)r);
            break;
        }

        case NetProtocols.SE_MECH_SHIELD_DEFENSE:
        {
            OnMechShieldDefence((MechShieldDefenseRequest)r);
            break;
        }

        case NetProtocols.SE_SHOW_SIDEEFFECT_TRIGGERED_EFFECT:
        {
            OnShowSideEffect((ShowSideEffectTriggeredRequest)r);
            break;
        }

        case NetProtocols.SE_CARD_ATTR_CHANGE:
        {
            OnCardAttributeChange((CardAttributeChangeRequest)r);
            break;
        }

        case NetProtocols.GAME_STOP_BY_WIN_REQUEST:
        {
            OnGameStopByWin((GameStopByWinRequest)r);
            break;
        }
        }
    }
Ejemplo n.º 7
0
 private Thread StartTheSaveAndSendThread(ClientRequestResponseBase crrMessage, ServerRequestBase serverMessage)
 {
     Thread thread = new Thread(() => SaveNSend(crrMessage, serverMessage));
     return thread;
 }
Ejemplo n.º 8
0
        private ClientRequestResponseBase SaveNSendSimulator(ClientRequestResponseBase crrMessage, ServerRequestBase serverMessage)
        {
            if (crrMessage.ClientRequestResponseType != ClientRequestResponseType.AsynchronousPaymentQuery)
                Save(crrMessage);

            ClientRequestResponseBase sdpResponse = null;
            var paymentResponse = _paymentResponseRepository.GetByTransRefId(new Guid(crrMessage.TransactionRefId)).OfType<PaymentResponse>().FirstOrDefault();
            if (paymentResponse != null)
            {
                sdpResponse = paymentResponse;
            }
            return sdpResponse;
        } 
Ejemplo n.º 9
0
        private ClientRequestResponseBase SaveNSend(ClientRequestResponseBase crrMessage, ServerRequestBase serverMessage)
        {
            if (crrMessage.ClientRequestResponseType != ClientRequestResponseType.AsynchronousPaymentQuery)
                Save(crrMessage);

            ClientRequestResponseBase sdpResponse = null;
            SendToHSenid(serverMessage, crrMessage, out sdpResponse);
            return sdpResponse;
        }
Ejemplo n.º 10
0
        SDPPaymentNotificationResponse ProcessSDPPaymentNotification(ServerRequestBase serverRequest, ClientRequestResponseBase crrRequest)
        {
            SDPPaymentNotificationResponse response = null;
            SDPPaymentNotificationRequest req = serverRequest as SDPPaymentNotificationRequest;
            try
            {
                _paymentRequestRepository.Save(crrRequest);
                response = new SDPPaymentNotificationResponse
                               {
                                   statusCode = "Success",
                                   statusDetail = "Success"
                               };
            }
            catch(Exception ex)
            {
                //error
                _auditLogRepository.AddLog(Guid.Empty, crrRequest.ClientRequestResponseType.ToString(), "To/From HSenid",
                                           "Error: " + ex.Message+"\n"+ex.InnerException.Message);
                response = new SDPPaymentNotificationResponse
                {
                    statusCode = "Failed",
                    statusDetail = "Failed"
                };
            }

            return response;
        }
Ejemplo n.º 11
0
        private void SendToHSenid(ServerRequestBase requestMessage, ClientRequestResponseBase crrMessage, out ClientRequestResponseBase sdpResponse)
        {
            string hsenidUrl = "";
            WebClient wc = new WebClient();

            string mssg = JsonConvert.SerializeObject(requestMessage);
            wc.Encoding = Encoding.UTF8;

            hsenidUrl = SdpHost.GetSdpPaymentUri(crrMessage.ClientRequestResponseType);

            _auditLogRepository.AddLog(crrMessage.DistributorCostCenterId,
                                       crrMessage.ClientRequestResponseType.ToString() + "Request", "To HSenid",
                                       string.Format("Url: {0}; JsonRequest: {1}.",
                                                     hsenidUrl, mssg));

            Uri uri = new Uri(hsenidUrl, UriKind.Absolute);

            string strResponse = wc.UploadString(uri, "POST", mssg);

            _auditLogRepository.AddLog(crrMessage.DistributorCostCenterId,
                                       crrMessage.ClientRequestResponseType.ToString() + "Response", "From HSenid",
                                       string.Format("Url: {0}; JsonRequest: {1}.",
                                                     hsenidUrl, strResponse));

            sdpResponse = _messageDeserialize.DeserializeSDPResponse(strResponse, crrMessage.ClientRequestResponseType);

            sdpResponse.DistributorCostCenterId = crrMessage.DistributorCostCenterId;

            //LogThis(sdpResponse);

            if (sdpResponse == null) return;

            if (sdpResponse.ClientRequestResponseType != ClientRequestResponseType.PaymentInstrument
                && sdpResponse.ClientRequestResponseType != ClientRequestResponseType.AsynchronousPaymentQuery
                )
            {
                _paymentResponseRepository.Save(sdpResponse);
            }
        }
Ejemplo n.º 12
0
 private void BroadcastRequest(ServerRequestBase request)
 {
     ClientA.SendMessage(request);
     ClientB.SendMessage(request);
 }
Ejemplo n.º 13
0
 public void Broadcast_AddRequestToOperationResponse(ServerRequestBase request)
 {
     ClientA.CurrentClientRequestResponseBundle.AttachedRequests.Add(request);
     ClientB.CurrentClientRequestResponseBundle.AttachedRequests.Add(request);
 }
Ejemplo n.º 14
0
 private void BroadCastRequest(ServerRequestBase request)
 {
     MyClientProxy?.CurrentClientRequestResponseBundle?.AttachedRequests.Add(request);
     MyEnemyPlayer?.MyClientProxy?.CurrentClientRequestResponseBundle?.AttachedRequests.Add(request);
 }
Ejemplo n.º 15
0
        public void ProcessClientRequest(ClientRequestResponseBase crrMessage, ServiceProvider serviceProvider, out ServerRequestBase serverReqBase)
        {
            if (crrMessage == null)
            {
                throw new Exception("Message null");
            }

            serverReqBase = new ServerRequestBase();
            string userName = "";
            string password = "******";
            string subscriberId = "tel:254701234563";
            string applicationId = "APP_000007";
            bool allowOverPayment = true, allowPartialPayment = true;
            string version = "1.0";
            string sourcesAddress = "hewani";
            string binaryHeader = "Content-Type:application/json";

            if (serviceProvider != null)
            {
                applicationId = serviceProvider.SdpAppId;
                subscriberId = serviceProvider.SubscriberId;
                password = serviceProvider.SdpPassword;
                allowOverPayment = serviceProvider.AllowOverPayment;
                allowPartialPayment = serviceProvider.AllowPartialPayment;
            }
            else
            {
                throw new Exception("This service provider is not registered.");
            }
            //
            if (crrMessage is PaymentInstrumentRequest)
            {
                PaymentInstrumentRequest pir = crrMessage as PaymentInstrumentRequest;
                SDPPaymentInstrumentRequest paymentIstReq = new SDPPaymentInstrumentRequest
                                                                {
                                                                    applicationId     = applicationId,
                                                                    password          = password,
                                                                    type              = pir.paymentInstrumentType,
                                                                    //subscriberId    = subscriberId
                                                                    subscriberId      = pir.SubscriberId
                                                                };

                serverReqBase = paymentIstReq;
            }
            if (crrMessage is PaymentRequest)
            {
                PaymentRequest apr         = crrMessage as PaymentRequest;
                SDPPaymentRequest sdpapr   = new SDPPaymentRequest();
                sdpapr.accountId                       = apr.AccountId.ToString();
                sdpapr.allowOverPayments = allowOverPayment ? AllOverPayment.Allow.ToString() : AllOverPayment.Disallow.ToString();
                sdpapr.allowPartialPayments = allowPartialPayment ? AllowPartialPayments.Allow.ToString() : AllowPartialPayments.Disallow.ToString();
                sdpapr.amount                          = apr.Amount.ToString();
                sdpapr.applicationId                   = applicationId;
                sdpapr.currency                        = apr.Currency;
                sdpapr.externalTrxId                   = apr.TransactionRefId.Replace("-","");
                sdpapr.extra = apr.Extra; //new Dictionary<string, string>();// {new string("tilNo","66363" )};
               // sdpapr.extra.Add("tillNo","66361"); 
                sdpapr.invoiceNo                       = apr.InvoiceNumber;
                sdpapr.orderNo                         = apr.OrderNumber;
                sdpapr.password                        = password;
                sdpapr.paymentInstrumentName           = apr.PaymentInstrumentName;
                //sdpapr.subscriberId                  = subscriberId;
                sdpapr.subscriberId                    = apr.SubscriberId;
                sdpapr.smsDescription                  = apr.smsDescription;
                
                serverReqBase = sdpapr;
            }
            if (crrMessage is PaymentQueryRequest)
            {
                PaymentQueryRequest apq = crrMessage as PaymentQueryRequest;
                SDPPaymentQueryRequest sdpapq = new SDPPaymentQueryRequest();

                sdpapq.applicationId = applicationId;
                sdpapq.internalTrxId = apq.TransactionRefId.ToString();
                sdpapq.password      = password;

                serverReqBase = sdpapq;
            }
            if(crrMessage is DocSMS)
            {
                DocSMS sms = crrMessage as DocSMS;
                SDPSMSRequest reqSMS = new SDPSMSRequest
                                        {
                                            applicationId = applicationId,
                                            password = password,
                                            destinationAddresses = sms.Recipitents.Select(n => "tel:" + n).ToList(),
                                            deliveryStatusRequest = 1,
                                            encoding = SDPSmsEncoding.Text,
                                            message = sms.SmsBody,
                                        };
            }
        }
Ejemplo n.º 16
0
        public void ProcessSDPRequest(ServerRequestBase sdpRequest, out ClientRequestResponseBase crrRequest, out string subcriberid, out Guid sip)
        {
            subcriberid = "";
            sip = Guid.Empty;
            ClientRequestResponseBase paymentRequest = null;
            Guid serviceProviderId = Guid.Empty;
            crrRequest = new ClientRequestResponseBase();
            if (sdpRequest is SDPPaymentNotificationRequest)
            {
                paymentRequest = _paymentResponseRepository.GetByTransRefId(
                    new Guid(((SDPPaymentNotificationRequest)sdpRequest)
                        .externalTrxId))
                        .OfType<PaymentResponse>().FirstOrDefault();

                if (paymentRequest != null)
                {
                    serviceProviderId = paymentRequest.DistributorCostCenterId;
                   
                }
                if (paymentRequest  is PaymentResponse)
                {
                    var respo = ((PaymentResponse) paymentRequest);
                    subcriberid = respo.SubscriberId;
                    sip = respo.DistributorCostCenterId;
                }

                SDPPaymentNotificationRequest sdpapn =
                    sdpRequest as SDPPaymentNotificationRequest;

                PaymentNotificationRequest apn = new PaymentNotificationRequest();

                apn.ClientRequestResponseType = ClientRequestResponseType.AsynchronousPaymentNotification;
                apn.DateCreated               = sdpapn.timestamp;
                apn.Id                        = Guid.NewGuid();
                apn.TransactionRefId          =ConstructMyGuid(sdpapn.externalTrxId).ToString();
                apn.SDPStatusCode             = sdpapn.statusCode;
                apn.SDPStatusDetail           = sdpapn.statusDetail;
                apn.SDPTimeStamp              = sdpapn.timestamp;
                apn.SDPTransactionRefId       = sdpapn.internalTrxId;
                apn.SDPPaidAmount             = Convert.ToDouble(sdpapn.paidAmount);
                apn.SDPTotalAmount            = Convert.ToDouble(sdpapn.totalAmount);
                apn.SDPBalanceDue             = Convert.ToDouble(sdpapn.balanceDue);
                apn.SDPCurrency               = sdpapn.currency;
                apn.SDPReferenceId            = sdpapn.referenceId;
                apn.DistributorCostCenterId   = serviceProviderId;
               
                crrRequest = apn;
            }
            else if (sdpRequest is SDPBuyGoodsNotificationRequest)
            {
                throw new Exception("Buy goods not in use");
                SDPBuyGoodsNotificationRequest sdpBg = sdpRequest as SDPBuyGoodsNotificationRequest;
                BuyGoodsNotificationRequest bgNotif = new BuyGoodsNotificationRequest();

                bgNotif.ClientRequestResponseType = ClientRequestResponseType.AsynchronousPaymentNotification;
                bgNotif.Currency = sdpBg.currency;
                bgNotif.Date = sdpBg.date;
                bgNotif.DateCreated = DateTime.Now;
                bgNotif.Id = Guid.NewGuid();
                bgNotif.MerchantBalance = Convert.ToDouble(sdpBg.merchantBalance);
                bgNotif.PaidAmount = Convert.ToDouble(sdpBg.paidAmount);
                bgNotif.ReceiptNumber = sdpBg.receiptNumber;
                bgNotif.SDPTransactionRefId = sdpBg.internalTrxId;
                bgNotif.StatusCode = sdpBg.statusCode;
                bgNotif.StatusDetail = sdpBg.statusDetail;
                bgNotif.SubscriberName = sdpBg.subscriberName;
                bgNotif.Time = sdpBg.time;

                crrRequest = bgNotif;
            }
        }