Ejemplo n.º 1
0
    protected override void OnMessageReceived(int _socket, int _connectionID, int _channelID, ref byte[] _buffer, int _bufferSize)
    {
        InfoManager.Log(identifier + sbName + _connectionID + sbSentAMessage);

        received = ProcessMessage(_buffer);
        ServerSide.ProcessRequest(received, _connectionID);
    }
        //Convert parameters into object, save to database, and return object
        public void DBSaveWinInfo(string mobile, int gameID, string gameToken, string objectsSelected)
        {
            try
            {
                string CMSPlayerID = ServerSide.DBGetCMSPlayerID(mobile);

                DataSet             result   = new DataSet();
                List <SqlParameter> spParams = new List <SqlParameter>();
                spParams.Add(new SqlParameter("@CMSPlayerID", CMSPlayerID));
                spParams.Add(new SqlParameter("@GameID", gameID));
                spParams.Add(new SqlParameter("@GameToken", gameToken));
                spParams.Add(new SqlParameter("@ObjectsSelected", objectsSelected));

                result = DataAcess.ExecuteQuerySP("PEC.TODO", spParams);
                if (result.Tables[0].Rows.Count > 0)
                {
                    GameNameForDisplay      = result.Tables[0].Rows[0]["GameName"].ToString();
                    ClosingCaption          = result.Tables[0].Rows[0]["ClosingCaption"].ToString();
                    PrizePickUpDescription  = result.Tables[0].Rows[0]["PrizePickupDescription"].ToString();
                    CallToActionCaption     = result.Tables[0].Rows[0]["CallToActionCaption"].ToString();
                    CallToActionText        = result.Tables[0].Rows[0]["CallToActionText"].ToString();
                    CallToActionIsScrolling = Convert.ToBoolean(result.Tables[0].Rows[0]["CallToActionScrolling"].ToString());
                }
                else
                {
                    throw new Exception("DBSaveWinInfo Failed");
                }
            }

            catch (SqlException ex)
            {
                string errorMessage = ex.Message;
                RemoveData();
            }
        }
Ejemplo n.º 3
0
 void Awake()
 {
     if (null == instance)
     {
         instance = this;
     }
 }
Ejemplo n.º 4
0
    protected override void OnConnected(int _socket, int _connectionID)
    {
        WorldState newWorldState = ServerSide.GenerateNewWorldState();

        ServerSide.instance.stateByConnection.Add(_connectionID, newWorldState);
        Send((object)newWorldState, connectionID, true);
    }
Ejemplo n.º 5
0
        public Form_server()
        {
            InitializeComponent();

            try
            {
                var server_ip   = ConfigurationManager.AppSettings["server_ip"].ToString();
                var server_port = ConfigurationManager.AppSettings["server_port"].ToString();

                textBox_ip.Text   = server_ip;
                textBox_port.Text = server_port;

                IPEndPoint ep = new IPEndPoint(IPAddress.Parse(server_ip),
                                               int.Parse(server_port));

                _server = new ServerSide(ep,
                                         int.Parse(textBox_maxClients.Text),
                                         int.Parse(textBox_maxReq.Text),
                                         int.Parse(textBox_blockTime.Text));

                SetBindings();

                //добавим тестового пользователя
                _server.UsersBase.Add(new KeyValuePair <string, string>("yv", "0000"));
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Критическая ошибка! [{ex.Message}]");
                _server?.StopServer();
                this.Close();
            }

            this.FormClosed += Form_server_FormClosed;
        }
Ejemplo n.º 6
0
 public void DBGetLogo(string mobile)
 {
     try
     {
         string              CMSPlayerID = ServerSide.DBGetCMSPlayerID(mobile);
         DataSet             result      = new DataSet();
         List <SqlParameter> spParams    = new List <SqlParameter>();
         spParams.Add(new SqlParameter("@CMSPlayerID", CMSPlayerID));
         result = DataAcess.ExecuteQuerySP("PEC.TODO", spParams);
         if (result.Tables[0].Rows.Count > 0)
         {
             MemoryStream ms    = new MemoryStream((byte[])result.Tables[0].Rows[0][""]);
             byte[]       bytes = ms.ToArray();
             logo = bytes;
         }
         else
         {
             logo = null;
         }
     }
     catch (SqlException ex)
     {
         string errorMessage = ex.Message;
         logo = null;
     }
 }
        public void DBExecuteRedemptionOption(string mobile, int offerID, int optionReferenceID)
        {
            try
            {
                OfferID           = offerID;
                OptionReferenceID = optionReferenceID;
                string              CMSPlayerID = ServerSide.DBGetCMSPlayerID(mobile);
                DataSet             result      = new DataSet();
                List <SqlParameter> spParams    = new List <SqlParameter>();
                spParams.Add(new SqlParameter("@CMSPlayerID", CMSPlayerID));
                spParams.Add(new SqlParameter("@OfferID", OfferID));
                spParams.Add(new SqlParameter("@OptionReferenceID", OptionReferenceID));

                result = DataAcess.ExecuteQuerySP("PEC.TODO", spParams);

                if (result.Tables[0].Rows.Count > 0)
                {
                    RedemptionExecutionSucess = true;
                    HeaderCaptionLine1        = result.Tables[0].Rows[0][""].ToString();
                    BodyCaptionLine1          = result.Tables[0].Rows[0][""].ToString();
                    HeaderCaptionLine2        = result.Tables[0].Rows[0][""].ToString();
                    BodyCaptionLine2          = result.Tables[0].Rows[0][""].ToString();
                    FooterCaptionLine1        = result.Tables[0].Rows[0][""].ToString();
                    FooterCaptionLine2        = result.Tables[0].Rows[0][""].ToString();

                    MemoryStream ms    = new MemoryStream((byte[])result.Tables[0].Rows[0][""]);
                    byte[]       bytes = ms.ToArray();
                    if (bytes != null)
                    {
                        BodyImage1 = bytes;
                    }
                    else
                    {
                        BodyImage1 = null;
                    }

                    MemoryStream bodyImage2MS    = new MemoryStream((byte[])result.Tables[0].Rows[0][""]);
                    byte[]       bodyImage2Bytes = bodyImage2MS.ToArray();
                    if (bodyImage2Bytes != null)
                    {
                        BodyImage2 = bodyImage2Bytes;
                    }
                    else
                    {
                        BodyImage2 = null;
                    }
                    BodyImage2 = bodyImage2Bytes;
                }
                else
                {
                    RemoveData();
                    RedemptionExecutionSucess = false;
                }
            }
            catch (SqlException ex)
            {
                string errorMessage = ex.Message;
                RemoveData();
            }
        }
Ejemplo n.º 8
0
        public void DBEnrollGuestInEvent(string mobile, int eventID, int optionReferenceID)
        {
            try
            {
                EventID           = eventID;
                OptionReferenceID = optionReferenceID;
                string              CMSPlayerID = ServerSide.DBGetCMSPlayerID(mobile);
                DataSet             result      = new DataSet();
                List <SqlParameter> spParams    = new List <SqlParameter>();
                spParams.Add(new SqlParameter("@CMSPlayerID", CMSPlayerID));
                spParams.Add(new SqlParameter("@EventID", eventID));
                result             = DataAcess.ExecuteQuerySP("PEC.TODO", spParams);
                HeaderCaptionLine1 = result.Tables[0].Rows[0]["HeaderCaptionLine1"].ToString();
                HeaderCaptionLine2 = result.Tables[0].Rows[0][""].ToString();
                IsEnrolled         = Convert.ToBoolean(result.Tables[0].Rows[0][""].ToString());
                ConfirmationNumber = result.Tables[0].Rows[0][""].ToString();
                MemoryStream bodyImage1MS   = new MemoryStream((byte[])result.Tables[0].Rows[0][""]);
                byte[]       bodyImage1Byte = bodyImage1MS.ToArray();
                BodyImage1 = bodyImage1Byte;

                MemoryStream bodyImage2MS   = new MemoryStream((byte[])result.Tables[0].Rows[0][""]);
                byte[]       bodyImage2Byte = bodyImage2MS.ToArray();
                BodyImage2 = bodyImage2Byte;

                FooterCaptionLine1 = result.Tables[0].Rows[0][""].ToString();
                FooterCaptionLine2 = result.Tables[0].Rows[0][""].ToString();
            }
            catch (SqlException ex)
            {
                string errorMessage = ex.Message;
                RemoveData();
            }
        }
        public void DBStartGame(string mobile, int gameID, long PromotionID)
        {
            try
            {
                string              CMSPlayerID = ServerSide.DBGetCMSPlayerID(mobile);
                StartGameReturn     data        = new StartGameReturn();
                DataSet             result      = new DataSet();
                List <SqlParameter> spParams    = new List <SqlParameter>();
                spParams.Add(new SqlParameter("@GameID", gameID));
                spParams.Add(new SqlParameter("@CMSPlayerID", CMSPlayerID));
                spParams.Add(new SqlParameter("@PromotionID", PromotionID));
                result = DataAcess.ExecuteQuerySP("PEC.MG_PROMOTION_StartGame", spParams);

                if (result.Tables[0].Rows.Count > 0)
                {
                    GameToken        = result.Tables[0].Rows[0]["GameToken"].ToString();
                    StartGameCaption = result.Tables[0].Rows[0]["StartGameCaption"].ToString();
                    StartGameText    = result.Tables[0].Rows[0]["StartGameText"].ToString();
                }
                else
                {
                    RemoveData();
                }
            }

            catch (SqlException ex)
            {
                string errorMessage = ex.Message;
                RemoveData();
            }
        }
Ejemplo n.º 10
0
        public void DBGetAccountBalancesSet(string mobile)
        {
            try
            {
                string              CMSPlayerID = ServerSide.DBGetCMSPlayerID(mobile);
                DataSet             result      = new DataSet();
                List <SqlParameter> spParams    = new List <SqlParameter>();
                spParams.Add(new SqlParameter("@CMSPlayerID", CMSPlayerID));
                result = DataAcess.ExecuteQuerySP("PEC.TODO", spParams);
                if (result.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < result.Tables[0].Rows.Count; i++)
                    {
                        Account newAccount = new Account();
                        newAccount.accountName    = result.Tables[0].Rows[i][""].ToString();
                        newAccount.accountBalance = result.Tables[0].Rows[i][""].ToString();

                        AccountBalances.Add(newAccount);
                    }
                }
                else
                {
                    AccountBalances = null;
                }
            }
            catch (SqlException ex)
            {
                string errorMessage = ex.Message;
            }
        }
Ejemplo n.º 11
0
        public void DBEnterRemoteEntry(string mobile, int promotionID)
        {
            PromotionID = promotionID;
            try
            {
                string CMSPlayerID = ServerSide.DBGetCMSPlayerID(mobile);

                DataSet             result   = new DataSet();
                List <SqlParameter> spParams = new List <SqlParameter>();
                spParams.Add(new SqlParameter("@CMSPlayerID", CMSPlayerID));
                spParams.Add(new SqlParameter("@PromotionID", promotionID));
                result = DataAcess.ExecuteQuerySP("PEC.TODO", spParams);

                if (result.Tables[0].Rows.Count > 0)
                {
                    UpdateEntryCount     = Convert.ToInt32(result.Tables[0].Rows[0]["UpdateEntryCount"].ToString());
                    RemoteEntryAvaliable = Convert.ToBoolean(result.Tables[0].Rows[0]["RemoteEntryAvaliable"].ToString());
                }
                else
                {
                    RemoveData();
                }
            }
            catch (SqlException ex)
            {
                string errorMessage = ex.Message;
                RemoveData();
            }
        }
Ejemplo n.º 12
0
        public void InitClient(string key)
        {
            var fighter = new StarFighter(Color.Red, new SizeF(10f, 10f), new Vector2F(200, 200), 0);

            fighter.Init();
            gameObjects.Add(key, fighter);
            Console.WriteLine("sending " + key + " objects");
            try
            {
                foreach (var obj in gameObjects)
                {
                    string typeName = obj.Value.GetType().Name.ToString();
                    Console.WriteLine("sending to " + key + " " + " of type" + typeName + " " + obj.ToString());
                    var item = ((IGame2DProperties)obj.Value);
                    var dat  = key + "," + item.Location.X + "," + item.Location.Y;
                    var type = (GameAction)Enum.Parse(typeof(GameAction), typeName);
                    ServerSide.SendData(type, dat, PlayingClients[key].Ns);
                }
                ServerSide.SendCommand(GameAction.Done, PlayingClients[key].Ns);
            }
            catch
            {
            }

            PlayingClients[key].status = "loaded";
            foreach (var obj in gameObjects)
            {
                obj.Value.Init();
            }
        }
 public async Task <double> GetQualityScoreAsync(IList <double> brisqueFeatures)
 {
     if (brisqueFeatures?.Count > 0)
     {
         return(await QualityScoreProvider.GetQualityScoreAsync(brisqueFeatures));
     }
     throw ServerSide.NoBrisqueFeatures();
 }
Ejemplo n.º 14
0
 public Service1()
 {
     InitializeComponent();
     server   = new ServerSide(5000);
     data     = new Dictionary <int, List <string> >();
     watchers = new Dictionary <string, IndexedWatcher>();
     server.ReceivedCommand += new ReceivedCommandDelegate(server_ReceivedCommand);
 }
Ejemplo n.º 15
0
        // Generate a one way hash, API does not specify implementation
        public void GenerateOneWayHash(string mobile)
        {
            //SHould set userToken = to something
            string CMSPlayerID = ServerSide.DBGetCMSPlayerID(mobile);
            //Generate hash based on mobile and current time
            string generatedHash = "hash";

            userToken = generatedHash;
        }
Ejemplo n.º 16
0
        public int OrderOf(string name)
        {
            var property = ServerSide.FirstOrDefault(k => k.Name.ToLower() == name.ToLower());

            if (property != null)
            {
                return(property.Order);
            }

            return(-1);
        }
Ejemplo n.º 17
0
        public void DBGetEventsScreenWrapper(string mobile)
        {
            try
            {
                string              CMSPlayerID = ServerSide.DBGetCMSPlayerID(mobile);
                DataSet             result      = new DataSet();
                List <SqlParameter> spParams    = new List <SqlParameter>();
                spParams.Add(new SqlParameter("@CMSPlayerID", CMSPlayerID));

                result = DataAcess.ExecuteQuerySP("PEC.TODO", spParams);

                if (result.Tables[0].Rows.Count > 0)
                {
                    Line1Caption = result.Tables[0].Rows[0][""].ToString();
                    Line1Data    = result.Tables[0].Rows[0][""].ToString();
                    Line2Caption = result.Tables[0].Rows[0][""].ToString();
                    Line2Data    = result.Tables[0].Rows[0][""].ToString();


                    DataSet             buttonDS     = new DataSet();
                    List <SqlParameter> buttonParams = new List <SqlParameter>();
                    buttonParams.Add(new SqlParameter("@CMSPlayerID", CMSPlayerID));
                    buttonDS = DataAcess.ExecuteQuerySP("PEC.TODO", buttonParams);

                    if (buttonDS.Tables[0].Rows.Count > 0)
                    {
                        for (int i = 0; i < buttonDS.Tables[0].Rows.Count; i++)
                        {
                            EventButton newButton = new EventButton();
                            newButton.ButtonCaption = result.Tables[0].Rows[i][""].ToString();
                            newButton.ButtonOrdPos  = Convert.ToInt32(result.Tables[0].Rows[i][""].ToString());
                            newButton.ButtonEventID = Convert.ToInt32(result.Tables[0].Rows[i][""].ToString());
                            MemoryStream ButtonMS    = new MemoryStream((byte[])result.Tables[0].Rows[i][""]);
                            byte[]       ButtonBytes = ButtonMS.ToArray();
                            newButton.ButtonImage = ButtonBytes;
                            Buttons.Add(newButton);
                        }
                    }
                    else
                    {
                        Buttons = null;
                    }
                }
                else
                {
                    RemoveData();
                }
            }
            catch (SqlException ex)
            {
                string errorMessage = ex.Message;
                RemoveData();
            }
        }
Ejemplo n.º 18
0
        public void DBListEntriesInNextDraw(string mobile, int promotionID)
        {
            try
            {
                PromotionID = promotionID;
                string              CMSPlayerID = ServerSide.DBGetCMSPlayerID(mobile);
                DataSet             result      = new DataSet();
                List <SqlParameter> spParams    = new List <SqlParameter>();
                spParams.Add(new SqlParameter("@CMSPlayerID", CMSPlayerID));
                spParams.Add(new SqlParameter("@PromotionID", PromotionID));
                result = DataAcess.ExecuteQuerySP("PEC.TODO", spParams);

                if (result.Tables[0].Rows.Count > 0)
                {
                    NextDrawDate       = Convert.ToDateTime(result.Tables[0].Rows[0]["NextDrawDate"].ToString());
                    NextDrawTime       = Convert.ToDateTime(result.Tables[0].Rows[0]["NextDrawTime"].ToString());
                    EntriesForNextDraw = Convert.ToInt32(result.Tables[0].Rows[0]["EntriesForNextDraw"].ToString());
                    IsDrumPopulated    = Convert.ToBoolean(result.Tables[0].Rows[0]["IsPopulated"].ToString());
                    SpecialMessage     = result.Tables[0].Rows[0]["SpecialMessage"].ToString();
                    if (IsDrumPopulated)
                    {
                        DataSet entryDS = new DataSet();
                        entryDS = DataAcess.ExecuteQuerySP("PEC.TODO", spParams);
                        if (entryDS.Tables[0].Rows.Count > 0)
                        {
                            for (int i = 0; i < entryDS.Tables[0].Rows.Count; i++)
                            {
                                string entryNum = entryDS.Tables[0].Rows[i]["EntryNumber"].ToString();
                                EntryNumbers.Add(entryNum);
                            }
                        }
                        else
                        {
                            EntryNumbers = null;
                        }
                    }
                    else
                    {
                        EntryNumbers = null;
                    }
                }
                else
                {
                    RemoveData();
                }
            }
            catch (SqlException ex)
            {
                string errorMessage = ex.Message;
                RemoveData();
            }
        }
Ejemplo n.º 19
0
        //DB Get Promotions Screen Wrapper from SQL Server
        public void DBGetPromotionsScreenWrapperReturn(string mobile)
        {
            try
            {
                string CMSPlayerID = ServerSide.DBGetCMSPlayerID(mobile);

                DataSet             result   = new DataSet();
                List <SqlParameter> spParams = new List <SqlParameter>();
                spParams.Add(new SqlParameter("@CMSPlayerID", CMSPlayerID));
                result = DataAcess.ExecuteQuerySP("PEC.PROMOTIONS_GetWrapper", spParams);

                if (result.Tables[0].Rows.Count > 0)
                {
                    Line1Caption = result.Tables[0].Rows[0]["Line1Caption"].ToString();
                    Line1Data    = result.Tables[0].Rows[0]["Line1Data"].ToString();
                    Line2Caption = result.Tables[0].Rows[0]["Line2Caption"].ToString();
                    Line2Data    = result.Tables[0].Rows[0]["Line2Data"].ToString();

                    DataSet             buttonDS     = new DataSet();
                    List <SqlParameter> buttonParams = new List <SqlParameter>();
                    buttonParams.Add(new SqlParameter("@CMSPlayerID", CMSPlayerID));
                    buttonDS = DataAcess.ExecuteQuerySP("PEC.PROMOTIONS_WrapperButtons", buttonParams);

                    if (buttonDS.Tables[0].Rows.Count > 0)
                    {
                        for (int i = 0; i < buttonDS.Tables[0].Rows.Count; i++)
                        {
                            PromoButton newButton = new PromoButton();
                            newButton.ButtonCaption = buttonDS.Tables[0].Rows[i]["ButtonCaption"].ToString();
                            newButton.ButtonOrdPos  = Convert.ToInt32(buttonDS.Tables[0].Rows[i]["ButtonOrdPos"].ToString());
                            Buttons.Add(newButton);
                        }
                    }
                    else
                    {
                        RemoveData();
                    }
                }
                else
                {
                    RemoveData();
                }
            }



            catch (SqlException ex)
            {
                RemoveData();
                string errorMessage = ex.Message;
            }
        }
        // TODO: Binary Data for background
        // LARS: What is the binary data I'm looking for here? Not sure based on API Doc
        public void DBGetIntervalsAndBackgrounds(string mobile, int gameID, int variantID)
        {
            string CMSPlayerID = ServerSide.DBGetCMSPlayerID(mobile);

            DataSet             result   = new DataSet();
            List <SqlParameter> spParams = new List <SqlParameter>();

            spParams.Add(new SqlParameter("@CMSPlayerID", CMSPlayerID));
            spParams.Add(new SqlParameter("@GameID", gameID));
            spParams.Add(new SqlParameter("@VariantID", variantID));

            result = DataAcess.ExecuteQuerySP("MG_PROMOTION_BACKGROUND_GetByGameID", spParams);

            if (result.Tables[0].Rows.Count > 0)
            {
                for (int j = 0; j < result.Tables[0].Rows.Count; j++)
                {
                    AttributeInfo gameAttributes = new AttributeInfo();
                    gameAttributes.GameName       = result.Tables[0].Rows[j]["gameName"].ToString();
                    gameAttributes.PageName       = result.Tables[0].Rows[j]["pageName"].ToString();
                    gameAttributes.TypeName       = result.Tables[0].Rows[j]["typename"].ToString();
                    gameAttributes.ObjectName     = result.Tables[0].Rows[j]["objectName"].ToString();
                    gameAttributes.AttributeName  = result.Tables[0].Rows[j]["attributeName"].ToString();
                    gameAttributes.AttributeValue = result.Tables[0].Rows[j]["attributeValue"].ToString();

                    DataSet             binaryData   = new DataSet();
                    List <SqlParameter> binaryParams = new List <SqlParameter>();
                    binaryParams.Add(new SqlParameter("@GameID", gameID));
                    binaryParams.Add(new SqlParameter("@VariantID", variantID));

                    binaryData = DataAcess.ExecuteQuerySP("TODO", binaryParams);

                    if (binaryData.Tables[0].Rows.Count > 0)
                    {
                        MemoryStream ms    = new MemoryStream((byte[])binaryData.Tables[0].Rows[0]["attributeBinaryData"]);
                        byte[]       bytes = ms.ToArray();
                        gameAttributes.AttributeBinaryValue = bytes;
                    }
                    else
                    {
                        gameAttributes.AttributeBinaryValue = null;
                    }
                    Attributes.Add(gameAttributes);
                }
            }

            else
            {
                RemoveData();
            }
        }
Ejemplo n.º 21
0
 public static MemoryStream GetMemoryStream(string filePath)
 {
     try
     {
         using (StreamReader reader = new StreamReader(filePath))
         {
             return(new MemoryStream(Encoding.UTF8.GetBytes(reader.ReadToEnd() ?? "")));
         }
     }
     catch (System.OutOfMemoryException) { throw ServerSide.OutOfMemoryWhileReadingStream(); }
     catch (System.IO.IOException) { throw ServerSide.IOErrorWhileReadingStream(); }
     catch (System.ArgumentNullException) { throw ServerSide.BufferNullToCreateMemoryStream(); }
     catch { throw ServerSide.StreamReadingFailure(); }
 }
Ejemplo n.º 22
0
    protected override void NetworkStart()
    {
        base.NetworkStart();

        if (!networkObject.IsServer)
        {
            Destroy(this);
        }
        else
        {
            Instance = this;
            InvokeRepeating("CheckAndRespawnItems", 0, 10);
        }
    }
Ejemplo n.º 23
0
        public Form_server()
        {
            InitializeComponent();

            FormClosing += Form_server_FormClosing;

            _serverSocket          = new ServerSide();
            _serverSocket.StopWord = "bye";

            BindUItoClientSide();

            GetHostIp();

            _bot = new Bot(_serverSocket.Send);
        }
Ejemplo n.º 24
0
        public static async Task <bool> Download(string url, string path)
        {
            try
            {
                using (var client = new WebClient())
                {
                    await client.DownloadFileTaskAsync(url, path);

                    return(true);
                }
            }
            catch (System.ArgumentNullException) { throw ServerSide.DownloadFailure("Null value for url or path"); }
            catch (System.Net.WebException ex) { throw ServerSide.UrlDownloadFailure(ex.Message + "|" + ex.ToString() + "|" + path); }
            catch (System.InvalidOperationException) { throw ServerSide.FileInUseError(); }
            catch (Exception ex) { throw new Exception(); }
        }
Ejemplo n.º 25
0
        //  public ConcurrentDictionary<string, int> scores = new Dictionary<string, int>();


        public void ConnectNewPlayingClient()
        {
            try
            {
                while (true)
                {
                    Console.WriteLine("Checking for playing clients");
                    try
                    {
                        tasks[0] = Task.Run(() =>
                        {
                            foreach (var client in ServerSide.ConnectClients.ConnectedClients.Values)
                            {
                                if (client.Connected)
                                {
                                    try
                                    {
                                        NetworkStream ns = client.GetStream();
                                        //byte[] b = new byte[sizeof(short)];
                                        //ns.Read(b, 0, b.Length);
                                        //var message = (GameAction)BitConverter.ToInt16(b, 0);
                                        var message = ServerSide.RecvCommand(ns);

                                        if (message == GameAction.Ready)
                                        {
                                            var key = ServerSide.RecvShortString(ns);
                                            client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
                                            Console.WriteLine("client address: " + client.Client.RemoteEndPoint.ToString() + "name:" + key + " playing");
                                            PlayingClients.TryAdd(key, new ClientMember(client, key, client.GetStream()));
                                            Console.WriteLine("initing " + key + " background transfer");
                                            InitClient(key);
                                            break;
                                        }
                                    }
                                    catch { Console.WriteLine("problem with user playing"); }
                                }
                            }
                        });
                    }
                    catch { Console.WriteLine("error"); }

                    Thread.Sleep(5000);
                }
            }
            catch { Console.WriteLine("Problem with while"); }
        }
Ejemplo n.º 26
0
        static void Main(string[] args)
        {
            TcpListener   socketListener = new TcpListener(8888);
            TcpClient     netClient      = default(TcpClient);
            StreamReader  sr;
            StringBuilder sb = new StringBuilder();

            socketListener.Start();
            sr = new StreamReader("c:\\test.txt");
            sb.Append(sr.ReadToEnd());
            while (true)
            {
                netClient = socketListener.AcceptTcpClient();
                Console.WriteLine("Accepted Connection From Client" + Environment.NewLine + "Client connected");
                ServerSide ss = new ServerSide();
                ss.startServerSide(netClient, sb);
            }
            socketListener.Stop();
        }
Ejemplo n.º 27
0
        public void DBPurchaseTicketsToEventWithPoints(string mobile, int eventID, int optionReferenceID, int ticketCountRequested)
        {
            try
            {
                EventID           = eventID;
                OptionReferenceID = optionReferenceID;
                string              CMSPlayerID = ServerSide.DBGetCMSPlayerID(mobile);
                DataSet             result      = new DataSet();
                List <SqlParameter> spParams    = new List <SqlParameter>();
                spParams.Add(new SqlParameter("@CMSPlayerID", CMSPlayerID));
                spParams.Add(new SqlParameter("@EventID", eventID));
                spParams.Add(new SqlParameter("@OptionReferenceID", optionReferenceID));
                spParams.Add(new SqlParameter("@TicketCountRequested", ticketCountRequested));

                result                   = DataAcess.ExecuteQuerySP("PEC.TODO", spParams);
                HeaderCaptionLine1       = result.Tables[0].Rows[0]["HeaderCaptionLine1"].ToString();
                HeaderCaptionLine2       = result.Tables[0].Rows[0][""].ToString();
                IsPurchaseSuccessful     = Convert.ToBoolean(result.Tables[0].Rows[0][""].ToString());
                NewPointsBalance         = float.Parse(result.Tables[0].Rows[0][""].ToString());
                IsEnrolled               = Convert.ToBoolean(result.Tables[0].Rows[0][""].ToString());
                ConfirmationNumber       = result.Tables[0].Rows[0][""].ToString();
                TicketCountAwarded       = Convert.ToInt32(result.Tables[0].Rows[0][""].ToString());
                IsOnWaitList             = Convert.ToBoolean(result.Tables[0].Rows[0][""].ToString());
                ExpectedResponseInterval = result.Tables[0].Rows[0][""].ToString();

                MemoryStream bodyImage1MS   = new MemoryStream((byte[])result.Tables[0].Rows[0][""]);
                byte[]       bodyImage1Byte = bodyImage1MS.ToArray();
                BodyImage1 = bodyImage1Byte;

                MemoryStream bodyImage2MS   = new MemoryStream((byte[])result.Tables[0].Rows[0][""]);
                byte[]       bodyImage2Byte = bodyImage2MS.ToArray();
                BodyImage2 = bodyImage2Byte;

                FooterCaptionLine1 = result.Tables[0].Rows[0][""].ToString();
                FooterCaptionLine2 = result.Tables[0].Rows[0][""].ToString();
            }
            catch (SqlException ex)
            {
                string errorMessage = ex.Message;
                RemoveData();
            }
        }
Ejemplo n.º 28
0
        public override void Update(GameTime gameTime)
        {
            foreach (var client in PlayingClients)
            {
                if (client.Value.status == "loaded")
                {
                    if (client.Value.Ns.DataAvailable)
                    {
                        try
                        {
                            //var sizeData = new byte[4];
                            //client.Value.Ns.Read(sizeData, 0, 4);
                            //var message = Encoding.ASCII.GetString(sizeData);

                            byte[] b = new byte[sizeof(short)];
                            client.Value.Ns.Read(b, 0, b.Length);
                            var message = (GameAction)BitConverter.ToInt16(b, 0);

                            // if (String.Compare(message, "Acce") == 0)
                            if (message == GameAction.Accelerate)
                            {
                                ((StarFighter)gameObjects[client.Value.key]).Accelerate();
                            }
                            if (message == GameAction.Deaccelerate)
                            {
                                ((StarFighter)gameObjects[client.Value.key]).Deaccelerate();
                            }
                            if (message == GameAction.TurnLeft)
                            {
                                ((StarFighter)gameObjects[client.Value.key]).TurnLeft();
                            }
                            if (message == GameAction.TurnRight)
                            {
                                ((StarFighter)gameObjects[client.Value.key]).TurnRight();
                            }
                        }
                        catch { }
                    }
                }

                foreach (var obj in gameObjects)
                {
                    obj.Value.Update(gameTime);
                }

                var fighters = gameObjects.Values.OfType <StarFighter>();
                if (client.Value.status == "loaded")
                {
                    foreach (var fighter in fighters)
                    {
                        //   client.Value.Ns.Read(new byte[4096], 0, 4096);
                        //short id = 0;// BitConverter.ToInt16(Encoding.ASCII.GetBytes(client.Value.key),0);
                        var datString = client.Value.key + "," + fighter.Angle + "," + fighter.Location.X + "," + fighter.Location.Y;
                        //  ServerSide.SendData(GameAction.Update, new short[] { id, (short)fighter.Angle, (short)fighter.Location.X, (short)fighter.Location.Y }, client.Value.Ns);
                        //  SendString("upfi", client.Value.key, );
                        ServerSide.SendData(GameAction.Update, datString, client.Value.Ns);
                        //SendString(client.Value.key, client.Value.key, null);
                        // SendObject("upfi", client.Value.key, client.Value.key + "," + fighter.Angle + "," + fighter.Location.X + "," + fighter.Location.Y);
                    }
                }
            }


            //foreach (var player in gameObjects.Values.OfType<StarFighter>())
            //{
            //    foreach (var bullet in gameObjects.Values.OfType<Projectile>())
            //    {
            //        var delx = player.Size.Width;
            //        var dely = player.Size.Height;
            //        if (bullet.InBounds(new BoundF(player.Location.X - delx, player.Location.Y - dely, player.Location.X + delx, player.Location.Y + dely)))
            //        {
            //            if (!bullet.ID.Contains(player.ID))
            //            {
            //                var id = bullet.ID.Split(',').Last();
            //                bullet.ToBeDestroyed = true;
            //                if (player.IsDead.IsNotTrue())
            //                {
            //                    player.IsDead = true;
            //                    scores[id]++;
            //                }
            //            }
            //        }
            //    }

            //}


            //var keys = gameObjects.Keys.ToArray<string>();
            //for (int i = 0; i < keys.Count<string>(); i++)
            //{
            //    var ass = gameObjects[keys[i]];
            //    if (ass.GetType() == typeof(Asteroid))
            //    {
            //        //  ((IGame2DProperties)ass).Location = ((IGame2DProperties)ass).KeepInBounds(bound).Location;
            //    }

            //}



            //var fighters = gameObjects.Values.OfType<StarFighter>();
            //foreach (var client in PlayingClients)
            //{
            //    if (client.Value.status == "loaded")
            //    {
            //        foreach (var fighter in fighters)
            //        {
            //            SendString("upfi", client.Value.key, client.Value.key + "," + fighter.Angle + "," + fighter.Location.X + "," + fighter.Location.Y);
            //            // SendObject("upfi", client.Value.key, client.Value.key + "," + fighter.Angle + "," + fighter.Location.X + "," + fighter.Location.Y);
            //        }
            //    }
            //}

            if (delClient)
            {
                var lst = new List <string>();
                foreach (var client in PlayingClients)
                {
                    if (!client.Value.Client.Connected)
                    {
                        lst.Add(client.Key);
                    }
                }

                foreach (var key in lst)
                {
                    PlayingClients.Remove(key);
                    if (gameObjects.ContainsKey(key))
                    {
                        gameObjects.Remove(key);
                    }
                }
                delClient = false;
            }

            if (GameInput.isKeyDown(Keys.Escape))
            {
                RunAgain = false;
                GameWindow.AudioPlayer.Item1.StopTrack("background");
                GameWindow.CurrentScene = NextScene;
                GameWindow.View.Init();
                gameObjects.Clear();
            }
        }
Ejemplo n.º 29
0
        public void DBGetEventDetails(string mobile, int eventID)
        {
            try
            {
                EventID = eventID;
                string              CMSPlayerID = ServerSide.DBGetCMSPlayerID(mobile);
                DataSet             result      = new DataSet();
                List <SqlParameter> spParams    = new List <SqlParameter>();
                spParams.Add(new SqlParameter("@CMSPlayerID", CMSPlayerID));
                spParams.Add(new SqlParameter("@EventID", eventID));
                result = DataAcess.ExecuteQuerySP("PEC.TODO", spParams);

                if (result.Tables[0].Rows.Count > 0)
                {
                    HeaderCaptionLine1 = result.Tables[0].Rows[0][""].ToString();
                    HeaderCaptionLine2 = result.Tables[0].Rows[0][""].ToString();
                    EventCaption       = result.Tables[0].Rows[0][""].ToString();
                    EventStartDate     = Convert.ToDateTime(result.Tables[0].Rows[0][""]);
                    EventStartTime     = Convert.ToDateTime(result.Tables[0].Rows[0][""]);
                    EventEndDate       = Convert.ToDateTime(result.Tables[0].Rows[0][""]);
                    EventEndTime       = Convert.ToDateTime(result.Tables[0].Rows[0][""]);
                    DisplayOptions     = Convert.ToBoolean(result.Tables[0].Rows[0][""]);
                    FooterCaptionLine1 = result.Tables[0].Rows[0][""].ToString();
                    FooterCaptionLine2 = result.Tables[0].Rows[0][""].ToString();
                    MemoryStream ms         = new MemoryStream((byte[])result.Tables[0].Rows[0]["LargeImage"]);
                    byte[]       largeImage = ms.ToArray();
                    EventLargeImage = largeImage;

                    if (DisplayOptions)
                    {
                        DataSet             optionDS     = new DataSet();
                        List <SqlParameter> optionParams = new List <SqlParameter>();
                        optionParams.Add(new SqlParameter("@CMSPlayerID", CMSPlayerID));
                        optionParams.Add(new SqlParameter("@EventID", EventID));
                        optionDS = DataAcess.ExecuteQuerySP("PEC.TODO", optionParams);
                        if (optionDS.Tables[0].Rows.Count > 0)
                        {
                            for (int i = 0; i < optionDS.Tables[0].Rows.Count; i++)
                            {
                                EventOption newEvent = new EventOption();
                                newEvent.OptionCaption    = optionDS.Tables[0].Rows[i]["OptionCaption"].ToString();
                                newEvent.OptionExecutable = Convert.ToBoolean(optionDS.Tables[0].Rows[i]["OptionExecutable"].ToString());
                                MemoryStream optionMS        = new MemoryStream((byte[])optionDS.Tables[0].Rows[i]["OptionImage"]);
                                byte[]       optionImageByte = optionMS.ToArray();
                                newEvent.OptionImage       = optionImageByte;
                                newEvent.OptionReferenceID = Convert.ToInt32(optionDS.Tables[0].Rows[i]["ReferenceID"].ToString());
                                EventOptions.Add(newEvent);
                            }
                        }
                        else
                        {
                            EventOptions = null;
                        }
                    }
                    else
                    {
                        EventOptions = null;
                    }
                }
                else
                {
                    RemoveData();
                }
            }
            catch (SqlException ex)
            {
                string errorMessage = ex.Message;
                RemoveData();
            }
        }
Ejemplo n.º 30
0
        public override void Update(GameTime gameTime)
        {
            foreach (var client in ServerSide.ConnectClients.ConnectedClients.Values)
            {
                if (client.Connected)
                {
                    try
                    {
                        NetworkStream ns      = client.GetStream();
                        var           message = ServerSide.RecvCommand(ns);

                        if (message == GameAction.Ready)
                        {
                            var key = ServerSide.RecvShortString(ns);

                            if (!PlayingClients.ContainsKey(key))
                            {
                                client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
                                Console.WriteLine("client address: " + client.Client.RemoteEndPoint.ToString() + "name:" + key + " playing");
                                PlayingClients.TryAdd(key, new ClientMember(client, key, client.GetStream()));                        //, sw, sr));
                                Console.WriteLine("initing " + key + " background transfer");
                                InitClient(key);


                                var pt = Parallel.ForEach <ClientMember>(PlayingClients.Values, (cl) =>
                                {
                                    if (fighter.Value != null)
                                    {
                                        var datString = key + "," + fighter.Value.Angle + "," + fighter.Value.Location.X + "," + fighter.Value.Location.Y + ",";
                                        gameObjects.TryAdd(key, fighter.Value);
                                        ServerSide.SendData(GameAction.NewPlayer, datString, cl.Ns);
                                    }
                                });

                                while (!pt.IsCompleted)
                                {
                                }

                                break;
                            }
                        }
                        //   ns.Close();
                    }
                    catch { Console.WriteLine("problem"); }
                }
            }



            var p = Parallel.ForEach <ClientMember>(PlayingClients.Values, (client) =>
            {
                if (client.status == "loaded")
                {
                    try
                    {
                        client.Ns = client.Client.GetStream();
                    }
                    catch { }

                    if (client.Ns.DataAvailable)
                    {
                        try
                        {
                            var message = ServerSide.RecvCommand(client.Ns);
                            var key     = ServerSide.RecvShortString(client.Ns);

                            if (message == GameAction.Accelerate)
                            {
                                ((StarFighter)gameObjects[key]).Accelerate();
                            }
                            if (message == GameAction.Deaccelerate)
                            {
                                ((StarFighter)gameObjects[key]).Deaccelerate();
                            }
                            if (message == GameAction.TurnLeft)
                            {
                                ((StarFighter)gameObjects[key]).TurnLeft();
                            }
                            if (message == GameAction.TurnRight)
                            {
                                ((StarFighter)gameObjects[key]).TurnRight();
                            }

                            client.ns.Read(new byte[ClientSide.Client.ReceiveBufferSize], 0, ClientSide.Client.ReceiveBufferSize);
                        }
                        catch { }
                    }

                    var fighters = gameObjects.Keys.OfType <StarFighter>();

                    foreach (var fighter in fighters)
                    {
                        var datString = fighter.ID + "," + fighter.Angle + "," + fighter.Location.X + "," + fighter.Location.Y + ",";
                        ServerSide.SendData(GameAction.Update, datString, client.Ns);
                    }
                }
            });

            while (!p.IsCompleted)
            {
            }
            newPlayer = false;

            foreach (var obj in gameObjects)
            {
                obj.Value.Update(gameTime);
            }


            //foreach (var player in gameObjects.Values.OfType<StarFighter>())
            //{
            //    foreach (var bullet in gameObjects.Values.OfType<Projectile>())
            //    {
            //        var delx = player.Size.Width;
            //        var dely = player.Size.Height;
            //        if (bullet.InBounds(new BoundF(player.Location.X - delx, player.Location.Y - dely, player.Location.X + delx, player.Location.Y + dely)))
            //        {
            //            if (!bullet.ID.Contains(player.ID))
            //            {
            //                var id = bullet.ID.Split(',').Last();
            //                bullet.ToBeDestroyed = true;
            //                if (player.IsDead.IsNotTrue())
            //                {
            //                    player.IsDead = true;
            //                    scores[id]++;
            //                }
            //            }
            //        }
            //    }

            //}


            //var keys = gameObjects.Keys.ToArray<string>();
            //for (int i = 0; i < keys.Count<string>(); i++)
            //{
            //    var ass = gameObjects[keys[i]];
            //    if (ass.GetType() == typeof(Asteroid))
            //    {
            //        //  ((IGame2DProperties)ass).Location = ((IGame2DProperties)ass).KeepInBounds(bound).Location;
            //    }

            //}



            //var fighters = gameObjects.Values.OfType<StarFighter>();
            //foreach (var client in PlayingClients)
            //{
            //    if (client.Value.status == "loaded")
            //    {
            //        foreach (var fighter in fighters)
            //        {
            //            SendString("upfi", client.Value.key, client.Value.key + "," + fighter.Angle + "," + fighter.Location.X + "," + fighter.Location.Y);
            //            // SendObject("upfi", client.Value.key, client.Value.key + "," + fighter.Angle + "," + fighter.Location.X + "," + fighter.Location.Y);
            //        }
            //    }
            //}

            // if (delClient)
            {
                var lst = new List <string>();
                foreach (var client in PlayingClients)
                {
                    if (!client.Value.Client.Connected)
                    {
                        lst.Add(client.Key);
                        client.Value.status = "disconnected";
                        delClient           = true;
                    }
                }

                if (delClient)
                {
                    foreach (var key in lst)
                    {
                        var c = new ClientMember(null, "", null);
                        var f = default(IGameBehavior);
                        PlayingClients.TryRemove(key, out c);
                        if (gameObjects.ContainsKey(key))
                        {
                            gameObjects.TryRemove(key, out f);
                        }
                    }
                    //    delClient = false;

                    //  tasks[1] = Task.Run(() =>{
                    for (int i = 0; i < ServerSide.ConnectClients.ConnectedClients.Count; i++)
                    {
                        try
                        {
                            if (!ServerSide.ConnectClients.ConnectedClients[i].Connected)
                            {
                                // disconnect clients
                                var key = ServerSide.ConnectClients.ConnectedClients[i].Client.RemoteEndPoint.ToString();
                                var t   = new TcpClient();
                                ServerSide.ConnectClients.ConnectedClients.TryRemove(i, out t);//.TryTake(out ServerSide.ConnectClients.ConnectedClients.ElementAt(i) );
                                i--;
                                Console.WriteLine("client " + key + " disconnected");
                            }
                        }
                        catch { }
                    }
                    delClient = false;
                }
                //  Console.WriteLine("ConnectReadyCheck Close..");
                // });
            }

            if (GameInput.isKeyDown(Keys.Escape))
            {
                RunAgain = false;
                GameWindow.AudioPlayer.Item1.StopTrack("background");
                GameWindow.CurrentScene = NextScene;
                GameWindow.View.Init();
                gameObjects.Clear();
            }
        }