예제 #1
0
파일: MyTasks.cs 프로젝트: sando87/IWAS
        private void OnRecv_ICDMessages(int clientID, ICD.HEADER o)
        {
            ICD.HEADER obj = o as ICD.HEADER;
            switch (obj.msgID)
            {
            case ICD.DEF.CMD_TaskIDList:
            case ICD.DEF.CMD_TaskLatestInfo:
                OnRecv_TaskInfo(obj);
                break;

            case ICD.DEF.CMD_ChatRoomList:
                OnRecv_ChatList(obj);
                break;

            case ICD.DEF.CMD_ChatRoomInfo:
                OnRecv_ChatRoomInfo(obj);
                break;

            case ICD.DEF.CMD_DelChatUsers:
                OnRecv_DelChatUser(obj);
                break;

            default:
                break;
            }
        }
예제 #2
0
        private void OnRecv_Login(ICD.HEADER obj)
        {
            ICD.ERRORCODE curErr = (ICD.ERRORCODE)obj.error;
            switch (curErr)
            {
            case ICD.ERRORCODE.NOERROR:
                MessageBox.Show(MSG_SUCCESS_LOGIN);
                {
                    this.Visible = false;
                    Home home = new Home();
                    home.ShowDialog();
                }
                break;

            case ICD.ERRORCODE.NoID:
                MessageBox.Show(MSG_UNREGIST_ID);
                break;

            case ICD.ERRORCODE.WorngPW:
                MessageBox.Show(MSG_WRONG_PW);
                break;

            default:
                break;
            }
        }
예제 #3
0
        private void OnRecvEditTask(int clientID, ICD.HEADER obj)
        {
            if (DEF.CMD_TaskLatestInfo == obj.msgID)
            {
                ICD.WorkList msg = (ICD.WorkList)obj;
                if (mTask.recordID != msg.works[0].recordID)
                {
                    return;
                }

                mTask = msg.works[0];
                updateTaskInfo();
                if (mTask.state == "완료")
                {
                    Close();
                }
                else if (mTask.state == "완료대기" && mTask.director == MyInfo.mMyInfo.userID)
                {
                    btnReport.Text    = "확인";
                    btnReport.Enabled = true;
                }
            }
            else if (DEF.CMD_ChatRoomInfo == obj.msgID)
            {
                ProcMsgList((ChatRoomInfo)obj);
            }
            else if (DEF.CMD_DelChatUsers == obj.msgID)
            {
                Close();
            }
        }
예제 #4
0
        private void Run_waitClient(object o)
        {
            while (true)
            {
                IPEndPoint remoteEP = new IPEndPoint(IPAddress.Any, PORTNUM);
                byte[]     recvBuf  = mServer.Receive(ref remoteEP);
                if (recvBuf == null || recvBuf.Length == 0)
                {
                    break;
                }

                string ipAddr = remoteEP.ToString();
                if (!mClients.ContainsKey(ipAddr))
                {
                    mClients[ipAddr] = new FifoBuffer(MAX_FIFO_BUF);
                }

                FifoBuffer fifoBuf = mClients[ipAddr];
                fifoBuf.Push(recvBuf, recvBuf.Length);

                while (true)
                {
                    int        len = fifoBuf.GetSize();
                    byte[]     buf = fifoBuf.readSize(len);
                    ICD.HEADER msg = ICD.HEADER.ConvertBytesToICDMessage(buf);
                    if (msg == null)
                    {
                        break;
                    }

                    fifoBuf.Pop(msg.msgSize);
                    OnProcRead?.Invoke(ipAddr, msg);
                }
            }
        }
예제 #5
0
파일: login.cs 프로젝트: sando87/IWAS
        private void OnRecv_Login(ICD.HEADER obj)
        {
            switch (obj.msgErr)
            {
            case ICD.DEF.ERR_NoError:
            {
                MessageBox.Show(MSG_SUCCESS_LOGIN);
                MyInfo.mMyInfo = obj as ICD.User;

                ICDPacketMgr.GetInst().OnRecv -= OnRecv_ICDMessages;
                Visible = false;

                MyTasks task = new MyTasks();
                task.Show();
                task.FormClosed += delegate {
                    Visible = true;
                    ICDPacketMgr.GetInst().OnRecv += OnRecv_ICDMessages;
                };
            }
            break;

            case ICD.DEF.ERR_NoID:
                MessageBox.Show(MSG_UNREGIST_ID);
                break;

            case ICD.DEF.ERR_WorngPW:
                MessageBox.Show(MSG_WRONG_PW);
                break;

            default:
                break;
            }
        }
예제 #6
0
파일: MyTasks.cs 프로젝트: sando87/IWAS
        private void MyTasks_Load(object sender, EventArgs e)
        {
            ICDPacketMgr.GetInst().OnRecv += OnRecv_ICDMessages;
            FormClosed += delegate {
                ICDPacketMgr.GetInst().OnRecv -= OnRecv_ICDMessages;
                Dispose();
                //Relese All
                //Close databases
                //Close Network Socket
                Process.GetCurrentProcess().Kill();
            };


            InitListView();

            ICD.HEADER msg = new ICD.HEADER();
            msg.FillClientHeader(ICD.DEF.CMD_TaskIDList);
            ICDPacketMgr.GetInst().sendMsgToServer(msg);

            /*
             * ICD.HEADER chatMsg = new ICD.HEADER();
             * chatMsg.FillClientHeader(ICD.DEF.CMD_ChatRoomList);
             * ICDPacketMgr.GetInst().sendMsgToServer(chatMsg);
             */
        }
예제 #7
0
파일: MyTasks.cs 프로젝트: sando87/IWAS
 private void OnRecv_DelChatUser(ICD.HEADER obj)
 {
     ICD.ChatRoomInfo msg = (ICD.ChatRoomInfo)obj;
     if (mChats.ContainsKey(msg.body.recordID))
     {
         mChats.Remove(msg.body.recordID);
         UpdateChatList();
     }
 }
예제 #8
0
파일: MyTasks.cs 프로젝트: sando87/IWAS
        private void OnRecv_ChatList(ICD.HEADER obj)
        {
            ICD.ChatRoomList msg = (ICD.ChatRoomList)obj;

            foreach (ICD.RoomInfo item in msg.body)
            {
                mChats[item.recordID] = item;
            }

            UpdateChatList();
        }
예제 #9
0
        private void ICD_NewUser(ICD.HEADER obj)
        {
            ICD.User msg = obj as ICD.User;

            if (DatabaseMgr.GetUserInfo(msg.userID) != null)
            {
                //send back error msg : same user id
            }
            else
            {
                //push db new user
                //ack good
            }
        }
예제 #10
0
        public Form1()
        {
            InitializeComponent();

            //Lambda express
            IcdMgr.OnRecv += (s, e) =>
            {
                ICD.HEADER obj = e as ICD.HEADER;
                MessageHandler(s, obj);
            };

            IcdMgr.StartServiceServer();

            DatabaseMgr.Open();
        }
예제 #11
0
파일: login.cs 프로젝트: sando87/IWAS
        private void OnRecv_NewUser(ICD.HEADER obj)
        {
            switch (obj.msgErr)
            {
            case ICD.DEF.ERR_NoError:
                MessageBox.Show(MSG_SUCCESS_NEWID);
                break;

            case ICD.DEF.ERR_HaveID:
                MessageBox.Show(MSG_ALREADY_ID);
                break;

            default:
                break;
            }
        }
예제 #12
0
        private void ICDMessage_Recv(int clientID, ICD.HEADER o)
        {
            ICD.HEADER obj = o as ICD.HEADER;
            switch ((ICD.COMMAND)obj.id)
            {
            case ICD.COMMAND.NewUser:
                OnRecv_NewUser(obj);
                break;

            case ICD.COMMAND.Login:
                OnRecv_Login(obj);
                break;

            default:
                break;
            }
        }
예제 #13
0
        private void OnRecv_NewUser(ICD.HEADER obj)
        {
            ICD.ERRORCODE curErr = (ICD.ERRORCODE)obj.error;
            switch (curErr)
            {
            case ICD.ERRORCODE.NOERROR:
                MessageBox.Show(MSG_SUCCESS_NEWID);
                break;

            case ICD.ERRORCODE.HaveID:
                MessageBox.Show(MSG_ALREADY_ID);
                break;

            default:
                break;
            }
        }
예제 #14
0
파일: DlgChatRoom.cs 프로젝트: sando87/IWAS
        private void OnProcChatRoom(int clientID, ICD.HEADER obj)
        {
            ICD.ChatRoomInfo msg = (ICD.ChatRoomInfo)obj;
            switch (msg.msgID)
            {
            case ICD.DEF.CMD_ChatRoomInfo:
                ProcMsgList(msg);
                break;

            case ICD.DEF.CMD_DelChatUsers:
                ProcDelUser(msg);
                break;

            default:
                break;
            }
        }
예제 #15
0
파일: login.cs 프로젝트: sando87/IWAS
        private void OnRecv_ICDMessages(int clientID, ICD.HEADER o)
        {
            ICD.HEADER obj = o as ICD.HEADER;
            switch (obj.msgID)
            {
            case ICD.DEF.CMD_NewUser:
                OnRecv_NewUser(obj);
                break;

            case ICD.DEF.CMD_Login:
                OnRecv_Login(obj);
                break;

            default:
                break;
            }
        }
예제 #16
0
파일: MyTasks.cs 프로젝트: sando87/IWAS
        private void OnRecv_ChatRoomInfo(ICD.HEADER obj)
        {
            ICD.ChatRoomInfo msg = (ICD.ChatRoomInfo)obj;
            foreach (int id in msg.body.taskIDs)
            {
                if (!mTasks.ContainsKey(id))
                {
                    continue;
                }

                mTasks[id].currentState = msg.body.state;
            }
            UpdateTaskList();

            //ICD.ChatRoomInfo msg = (ICD.ChatRoomInfo)obj;
            //mChats[msg.body.recordID] = msg.body;
            //UpdateChatList();
        }
예제 #17
0
        private void OnRecvUserList(int clientID, ICD.HEADER obj)
        {
            if (ICD.DEF.CMD_UserList == obj.msgID)
            {
                ICD.Message msg   = obj as ICD.Message;
                string[]    infos = msg.message.Split(',');

                lvUserlist.Items.Clear();
                mUserList.Clear();
                foreach (string info in infos)
                {
                    if (info.Length > 0)
                    {
                        mUserList.Add(info);
                        lvUserlist.Items.Add(info);
                    }
                }
            }
        }
예제 #18
0
        private void Run_waitClient(object o)
        {
            TcpClient     client  = (TcpClient)o;
            string        ipAddr  = ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString();
            NetworkStream stream  = client.GetStream();
            FifoBuffer    fifoBuf = new FifoBuffer(MAX_FIFO_BUF);

            byte[] buff = new byte[MAX_SOCKET_BUF];
            while (true)
            {
                int nBytes = 0;
                try
                {
                    nBytes = stream.Read(buff, 0, buff.Length);
                    if (nBytes == 0)
                    {
                        break;
                    }
                }
                catch (Exception e) { LOG.echo(e.ToString()); break; }

                fifoBuf.Push(buff, nBytes);

                while (true)
                {
                    int        len = fifoBuf.GetSize();
                    byte[]     buf = fifoBuf.readSize(len);
                    ICD.HEADER msg = ICD.HEADER.ConvertBytesToICDMessage(buf);
                    if (msg == null)
                    {
                        break;
                    }

                    fifoBuf.Pop(msg.msgSize);
                    OnProcRead?.Invoke(ipAddr, msg);
                }
            }

            fifoBuf.Clear();
            stream.Close();
            CloseClient(ipAddr);
        }
예제 #19
0
        private void MessageHandler(int clientID, ICD.HEADER obj)
        {
            var id = obj.id;

            switch (id)
            {
            case 0:
                ICD_NewUser(obj);
                break;

            case 1:
                ICD_Login(clientID, obj);
                break;

            case 2:
                ICD_Logout(obj);
                break;

            default:
                break;
            }
        }
예제 #20
0
        private void ICD_Login(int clientID, ICD.HEADER obj)
        {
            ICD.User msg = obj as ICD.User;
            DataRow  row = DatabaseMgr.GetUserInfo(msg.userID);

            if (row != null)
            {
                //if(isOKpassword)
                {
                    //loginUser();
                    //ack good
                }
                //else
                {
                    //send back error msg : wrong password
                }
            }
            else
            {
                //send back error msg : no user id
            }
        }
예제 #21
0
파일: MyTasks.cs 프로젝트: sando87/IWAS
        private void OnRecv_TaskInfo(ICD.HEADER obj)
        {
            if (ICD.DEF.ERR_NoError != obj.msgErr)
            {
                LOG.warn();
                return;
            }

            ICD.WorkList task = (ICD.WorkList)obj;
            foreach (var item in task.works)
            {
                if (item.state == "완료")
                {
                    mTasks.Remove(item.recordID);
                }
                else
                {
                    mTasks[item.recordID] = item;
                }
            }
            UpdateTaskList();
        }
예제 #22
0
        private bool pushPacket(ref ClientBuf client)
        {
            long nRecvLen = client.mem.Length;

            byte[] buf      = client.mem.GetBuffer();
            int    headSize = ICD.HEADER.HeaderSize();

            if (nRecvLen < headSize)
            {
                return(false);
            }

            ICD.HEADER head = ICD.HEADER.GetHeaderInfo(buf);
            if (head.sof != (uint)ICD.MAGIC.SOF)
            {
                client.mem = new MemoryStream(MAX_CLIENT_BUF);
                return(false);
            }

            uint msgSize = head.size;

            if (nRecvLen < msgSize)
            {
                return(false);
            }

            QueuePack pack = new QueuePack();

            pack.ClientID = client.id;
            pack.size     = msgSize;
            pack.buf      = new byte[msgSize];
            Array.Copy(buf, pack.buf, msgSize);
            mQueue.Enqueue(pack);
            client.mem = new MemoryStream(MAX_CLIENT_BUF);

            return(true);
        }
예제 #23
0
 private void btnUpdate_Click(object sender, EventArgs e)
 {
     ICD.HEADER msg = new ICD.HEADER();
     msg.FillClientHeader(ICD.DEF.CMD_UserList);
     ICDPacketMgr.GetInst().sendMsgToServer(msg);
 }
예제 #24
0
 public void sendMsgToClient(int clientID, ICD.HEADER obj)
 {
     byte[] buf = obj.Serialize();
     NetworkMgr.GetInst().WriteToClient(clientID, buf);
 }
예제 #25
0
 public void sendMsgToServer(ICD.HEADER obj)
 {
     byte[] buf = obj.Serialize();
     NetworkMgr.GetInst().WriteToClient(0, buf);
 }
예제 #26
0
 private void ICD_Logout(ICD.HEADER obj)
 {
 }