Beispiel #1
0
        public void OnDataReceived(IAsyncResult asyn)
        {
            try
            {
                SocketPacket socketData = (SocketPacket)asyn.AsyncState;

                int bytesReceived = 0;
                bytesReceived = socketData.m_currentSocket.EndReceive(asyn);
                byte[] buffer = new byte[bytesReceived + 1];

                buffer = socketData.dataBuffer;

                IFormatter formatter = new BinaryFormatter();
                Stream     stream    = new MemoryStream();

                stream.Write(buffer, 0, buffer.Length);
                stream.Seek(0, 0);

                tet_network_object objReceived = (tet_network_object)formatter.Deserialize(stream);

                parseObject(objReceived);

                stream.Close();

                WaitForData(socketData.m_currentSocket);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Something bad happened : " + ex.Message, "Battle Tetrix", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                Application.Restart();
            }
        }
Beispiel #2
0
        private void parseObject(tet_network_object objReceived)
        {
            //tet_network_object received = (tet_network_object)objReceived;

            //mainWindow.appendMatrixToDebug(objReceived);

            if (mainWindow.blockLogic.oldReceivedObject != null)
            {
                if (objReceived.enemyScore != mainWindow.blockLogic.oldReceivedObject.enemyScore)
                {
                    mainWindow.drawHisScore(mainWindow.graphicsObj2, objReceived.enemyScore);
                }
                if (objReceived.enemyNextShape != mainWindow.blockLogic.oldReceivedObject.enemyNextShape)
                {
                    mainWindow.drawHisNexShape(mainWindow.graphicsObj2, objReceived.enemyNextShape);
                }
                mainWindow.drawHisMatrix(mainWindow.graphicsObj2, objReceived.enemyColorMatrix);
            }
            else
            {
                mainWindow.drawHisMatrix(mainWindow.graphicsObj2, objReceived.enemyColorMatrix);
                mainWindow.drawHisScore(mainWindow.graphicsObj2, objReceived.enemyScore);
                mainWindow.drawHisNexShape(mainWindow.graphicsObj2, objReceived.enemyNextShape);
            }

            mainWindow.blockLogic.oldReceivedObject = objReceived;
        }
Beispiel #3
0
        internal void sendMsgToClient(tet_network_object objToSend)
        {
            IFormatter formatter = new BinaryFormatter();
            Stream     stream    = new MemoryStream();

            formatter.Serialize(stream, objToSend);

            byte[] buffer = ((MemoryStream)stream).ToArray();
            m_socWorker[0].Send(buffer, buffer.Length, 0);
        }
Beispiel #4
0
        internal void sendMsgToClient(tet_network_object objToSend)
        {
            IFormatter formatter = new BinaryFormatter();
            Stream stream = new MemoryStream();

            formatter.Serialize(stream, objToSend);

            byte[] buffer = ((MemoryStream)stream).ToArray();
            m_clientSocket.Send(buffer, buffer.Length, 0);
        }
Beispiel #5
0
        private void parseObject(tet_network_object objReceived)
        {
            if (mainWindow.blockLogic.oldReceivedObject != null)
            {
                if (objReceived.enemyScore != mainWindow.blockLogic.oldReceivedObject.enemyScore)
                    mainWindow.drawHisScore(mainWindow.graphicsObj2, objReceived.enemyScore);
                if (objReceived.enemyNextShape != mainWindow.blockLogic.oldReceivedObject.enemyNextShape)
                    mainWindow.drawHisNexShape(mainWindow.graphicsObj2, objReceived.enemyNextShape);
                mainWindow.drawHisMatrix(mainWindow.graphicsObj2, objReceived.enemyColorMatrix);
            }
            else
            {
                mainWindow.drawHisMatrix(mainWindow.graphicsObj2, objReceived.enemyColorMatrix);
                mainWindow.drawHisScore(mainWindow.graphicsObj2, objReceived.enemyScore);
                mainWindow.drawHisNexShape(mainWindow.graphicsObj2, objReceived.enemyNextShape);
            }

            mainWindow.blockLogic.oldReceivedObject = objReceived;
        }