Ejemplo n.º 1
0
        async void Clicked_Create(object sender, System.EventArgs e)
        {
            //string action = await App.Current.MainPage.DisplayActionSheet("Room Create #General LEGION KOR ", "Cancel", null, "Individual", "Local", "Global");

            string action = await App.Current.MainPage.DisplayPromptAsync("room create", "enter room name");

            if (action == null)
            {
                return;
            }

            if (action.Length > 1024)
            {
                await App.Current.MainPage.DisplayAlert("name checker", "size is long", "ok");

                return;
            }

            NetProcess.SendMakeRoom(User.CacheData.UserName + "_" + action);

            //switch (action)
            //{
            //    case "Individual":
            //    case "Local":
            //    case "Global":
            //        NetProcess.SendMakeRoom(User.CacheData.UserName + "_#" + action);
            //        break;
            //    default:
            //        {
            //            if (action != "Cancel")
            //                NetProcess.SendMakeRoom(User.CacheData.UserName + "_" + "general");
            //        }
            //        break;
            //}
        }
Ejemplo n.º 2
0
        async void OnRoomEnterClicked(object sender, EventArgs args)
        {
            Button button = sender as Button;

            int id = Convert.ToInt32(button.CommandParameter.ToString());

            NetProcess.SendEnterRoom(id);
        }
Ejemplo n.º 3
0
        public void StartClient(string address, int port)
        {
            // Connect to a remote device.
            try
            {
                IPAddress ip = IPAddress.Parse(address);

                IPEndPoint remoteEP = new IPEndPoint(ip, port);

                if (socket != null)
                // Create a TCP/IP socket.
                {
                    if (socket.Connected == true)
                    {
                        //이미 접속은 했는데 로그인 실패면 다시 한다.
                        if (User.LoginSuccess == true)
                        {
                            return;
                        }
                    }

                    socket.Dispose();
                    socket = null;
                    socket = new Socket(AddressFamily.InterNetwork,
                                        SocketType.Stream, ProtocolType.Tcp);
                }
                else
                {
                    socket = new Socket(AddressFamily.InterNetwork,
                                        SocketType.Stream, ProtocolType.Tcp);
                }


                socket.ReceiveTimeout = 500;
                socket.SendTimeout    = 2000;

                User.LoginSuccess = false;

                var mainpage = (MainPage)Application.Current.MainPage;
                mainpage.setting.UpdateLoginState("(dis connect)");


                socket.Connect(remoteEP);

                if (socket.Connected == true)
                {
                    NetProcess.SendVersion();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Ejemplo n.º 4
0
        public MainChatViewModel()
        {
            // Initialize with default values
            Messages = new ObservableRangeCollection <Message>();
            RoomUser = new ObservableRangeCollection <ChatRoomUser>();


            SendCommand = new Command(() =>
            {
            });

            ExitCommand = new Command(() =>
            {
                var mainpage = (MainPage)Application.Current.MainPage;

                NetProcess.SendLeaveRoom(User.CurrentChatViewNumber);
            });

            LocationCommand = new Command(async() =>
            {
                try
                {
                    var local = await CrossGeolocator.Current.GetPositionAsync();
                    var map   = $"https://maps.googleapis.com/maps/api/staticmap?center={local.Latitude.ToString(CultureInfo.InvariantCulture)},{local.Longitude.ToString(CultureInfo.InvariantCulture)}&zoom=17&size=400x400&maptype=street&markers=color:red%7Clabel:%7C{local.Latitude.ToString(CultureInfo.InvariantCulture)},{local.Longitude.ToString(CultureInfo.InvariantCulture)}&key=";

                    var message = new Message
                    {
                        Text            = "I am here",
                        AttachementUrl  = map,
                        MessageType     = Message.type.Outgoing,
                        MessageDateTime = DateTime.Now
                    };

                    Messages.Add(message);
                }
                catch (Exception ex)
                {
                }
            });
        }
Ejemplo n.º 5
0
        private void NetworkProcess()
        {
            //network
            {
                //network thread
                Task.Run(() =>
                {
                    while (true)
                    {
                        try
                        {
                            NetProcess.start();
                            NetProcess.client.PacketRecvSync2();
                            NetProcess.Loop();

                            Thread.Sleep(10);
                        }catch (Exception e)
                        {
                        }
                    }
                });
            }
        }
Ejemplo n.º 6
0
        static public void Loop()
        {
            if (client.socket == null || client.socket.Connected == false)
            {
                return;
            }

            CompletePacket data;

            if (client.PacketQueue.TryDequeue(out data) == true)
            {
                try
                {
                    switch (data.Protocol)
                    {
                    case (int)PROTOCOL.IdPktVersionRes:
                    {
                        VERSION_RES res = new VERSION_RES();
                        res = VERSION_RES.Parser.ParseFrom(data.Data);

                        var currentVersion = VersionTracking.CurrentVersion;

                        double myversion;
                        if (double.TryParse(currentVersion, out myversion) == false)
                        {
                        }

                        const Double Eps = 0.000000000000001;

                        User.Version = res.VarVersion;

                        if (Math.Abs(res.VarVersion - myversion) > Eps)
                        {
                            //첫 검수라 임시 주석 2번째 패치 부터는 활성화
                            if (Device.RuntimePlatform == Device.Android && User.OnceVersionNotify == false)
                            {
                                Device.BeginInvokeOnMainThread(() =>
                                    {
                                        User.OnceVersionNotify = true;
                                        DependencyService.Get <Toast>().Notification("New Version Updated");
                                    });
                            }
                        }


                        SQLLiteDB.LoadCacheData();
                        if (User.CacheData.UserName != null)
                        {
                            NetProcess.SendLogin(User.CacheData.UserName, User.CacheData.Passwd);
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktLoginRes:
                    {
                        LOGIN_RES res = new LOGIN_RES();
                        res = LOGIN_RES.Parser.ParseFrom(data.Data);

                        var mainpage = (MainPage)Application.Current.MainPage;

                        if (res.VarCode == ErrorCode.Success)
                        {
                            User.LoginSuccess = true;
                            SQLLiteDB.Upsert(User.CacheData.FontSize, User.CacheData.BibleName, User.CacheData.Chapter, User.CacheData.Verse,
                                             User.CacheData.UserName, User.CacheData.Passwd);

                            Device.BeginInvokeOnMainThread(() =>
                                {
                                    mainpage.setting.UpdateLoginState("(Success)");
                                    mainpage.setting.UpdateNameEntry(User.CacheData.UserName);

                                    var page        = mainpage.CurrentView();
                                    var settingview = page as SettingView;

                                    if (settingview == null)
                                    {
                                        mainpage.LoadLobby();
                                    }
                                });
                        }
                        else
                        {
                            Device.BeginInvokeOnMainThread(() =>
                                {
                                    mainpage.setting.UpdateLoginState("(Failed)");
                                });

                            User.LoginSuccess = false;
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktRoomListRes:
                    {
                        ROOM_LIST_RES res = new ROOM_LIST_RES();
                        res = ROOM_LIST_RES.Parser.ParseFrom(data.Data);

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainpage = (MainPage)Application.Current.MainPage;

                                RoomsPageView roompage = mainpage.lobby.roompage as RoomsPageView;

                                roompage?.LoadRoomList(res);
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktNoticeRes:
                    {
                        NOTICE_RES res = new NOTICE_RES();
                        res = NOTICE_RES.Parser.ParseFrom(data.Data);

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainpage = (MainPage)Application.Current.MainPage;

                                mainpage.alarm.LoadList(res);
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktMailListRes:
                    {
                        MAIL_LIST_RES res = new MAIL_LIST_RES();
                        res = MAIL_LIST_RES.Parser.ParseFrom(data.Data);

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainpage = (MainPage)Application.Current.MainPage;

                                mainpage.mail.LoadList(res);
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktPrayMessageRes:
                    {
                        PRAY_MESSAGE_RES res = new PRAY_MESSAGE_RES();
                        res = PRAY_MESSAGE_RES.Parser.ParseFrom(data.Data);

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainpage = (MainPage)Application.Current.MainPage;

                                PrayView prayview = mainpage.lobby.praypage as PrayView;

                                prayview?.LoadPrayList(res);
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktCreateRoomRes:
                    {
                        CREATE_ROOM_RES res = new CREATE_ROOM_RES();
                        res = CREATE_ROOM_RES.Parser.ParseFrom(data.Data);

                        if (res.VarCode != ErrorCode.Success)
                        {
                            break;
                        }

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainpage = (MainPage)Application.Current.MainPage;

                                RoomsPageView roompage = mainpage.lobby.roompage as RoomsPageView;

                                User.RoomIdList.Add(res.VarRoomId);

                                {
                                    User.CurrentChatViewNumber = res.VarRoomId;
                                    var chatview = new MainChatView();
                                    mainpage.lobby.chatpage.Add(res.VarRoomId, chatview);
                                    MainChatView chatpage = chatview;

                                    mainpage.LoadView(chatpage);
                                }
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktEnterRoomRes:
                    {
                        ENTER_ROOM_RES res = new ENTER_ROOM_RES();
                        res = ENTER_ROOM_RES.Parser.ParseFrom(data.Data);

                        if (res.VarCode != ErrorCode.DuplicateEnterRoom && res.VarCode != ErrorCode.Success)
                        {
                            break;
                        }

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                try
                                {
                                    var mainpage = (MainPage)Application.Current.MainPage;

                                    RoomsPageView roompage = mainpage.lobby.roompage as RoomsPageView;

                                    User.RoomIdList.Add(res.VarRoomId);
                                    {
                                        User.CurrentChatViewNumber = res.VarRoomId;

                                        MainChatView outivew;

                                        mainpage.lobby.chatpage.TryGetValue(res.VarRoomId, out outivew);
                                        if (outivew == null)     //없으면 새로 만들어서 넣는다.
                                        {
                                            var chatview = new MainChatView();
                                            mainpage.lobby.chatpage.Add(res.VarRoomId, chatview);
                                            mainpage.LoadView(chatview);

                                            foreach (var msg in res.VarMessages)
                                            {
                                                chatview.ReceiveMessage(msg.VarMessage, msg.VarName, msg.VarTime);
                                            }

                                            chatview.ScrollEnd();
                                        }
                                        else      //이미 존재하는 방이면 해당 방에 넣는다.
                                        {
                                            mainpage.LoadView(outivew);
                                            outivew.ScrollEnd();
                                        }
                                    }
                                }
                                catch (Exception e)
                                {
                                }
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktRoomPassThroughRes:
                    {
                        ROOM_PASS_THROUGH_RES res = new ROOM_PASS_THROUGH_RES();
                        res = ROOM_PASS_THROUGH_RES.Parser.ParseFrom(data.Data);
                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainpage = (MainPage)Application.Current.MainPage;


                                MainChatView outivew;

                                mainpage.lobby.chatpage.TryGetValue(res.VarRoomNumber, out outivew);
                                if (outivew == null)
                                {
                                    return;
                                }

                                foreach (var msg in res.VarMessages)
                                {
                                    outivew.ReceiveMessage(msg.VarMessage, msg.VarName, msg.VarTime);
                                }

                                outivew.ScrollEnd();
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktLeaveRoomRes:
                    {
                        LEAVE_ROOM_RES res = new LEAVE_ROOM_RES();
                        res = LEAVE_ROOM_RES.Parser.ParseFrom(data.Data);

                        var mainpage = (MainPage)Application.Current.MainPage;

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                MainChatView outivew;

                                mainpage.lobby.chatpage.TryGetValue(res.VarRoomNumber, out outivew);
                                if (outivew == null)
                                {
                                    return;
                                }

                                outivew.UserList.Remove(res.VarName);

                                if (res.VarName == User.CacheData.UserName)
                                {
                                    User.RoomIdList.Remove(res.VarRoomNumber);

                                    mainpage.lobby.chatpage.Remove(res.VarRoomNumber);

                                    mainpage.lobby.LoadRoomPageView();
                                }
                                else
                                {
                                    MainChatView chatpage = outivew as MainChatView;
                                    chatpage.ReceiveMessage(res.VarName + " leaved.",
                                                            res.VarName, Message.type.Info);
                                }
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktAudioMessageRes:
                    {
                        AUDIO_MESSAGE_RES res = new AUDIO_MESSAGE_RES();
                        res = AUDIO_MESSAGE_RES.Parser.ParseFrom(data.Data);

                        foreach (var msg in res.VarMessage)
                        {
                            StreamWrapper wra = new StreamWrapper();
                            wra.stream = new MemoryStream(msg.ToByteArray());
                            wra.pos    = res.VarPos;
                            AudioStream.Enqueue(wra);
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktBitmapMessageRes:
                    {
                        BITMAP_MESSAGE_RES res = new BITMAP_MESSAGE_RES();
                        res = BITMAP_MESSAGE_RES.Parser.ParseFrom(data.Data);

                        foreach (var msg in res.VarMessage)
                        {
                            StreamWrapper wra = new StreamWrapper();
                            wra.stream = new MemoryStream(msg.ToByteArray());
                            wra.pos    = res.VarPos;
                            JpegStream.Enqueue(wra);
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktNewUserInRoomNty:
                    {
                        NEW_USER_IN_ROOM_NTY res = new NEW_USER_IN_ROOM_NTY();
                        res = NEW_USER_IN_ROOM_NTY.Parser.ParseFrom(data.Data);

                        var mainpage = (MainPage)Application.Current.MainPage;


                        Device.BeginInvokeOnMainThread(() =>
                            {
                                MainChatView outivew;

                                mainpage.lobby.chatpage.TryGetValue(res.VarRoomUser.VarRoomNumber, out outivew);
                                if (outivew == null)
                                {
                                    return;
                                }

                                outivew.UserList.Add(res.VarRoomUser.VarName);

                                if (res.VarType == 1)
                                {
                                    if (res.VarRoomUser.VarName != User.CacheData.UserName)
                                    {
                                        outivew.ReceiveMessage(res.VarRoomUser.VarName + " entered.",
                                                               res.VarRoomUser.VarName, Message.type.Info);
                                    }
                                }
                            });
                    }
                    break;
                    }
                }
                catch (Exception ex)
                {
                    Console.Write(ex.ToString());
                }
            }
        }
Ejemplo n.º 7
0
 async void OnSendClicked(object sender, EventArgs args)
 {
     NetProcess.SendRoomMessage(entry_message.Text);
 }