Beispiel #1
0
 public Room(SocketModel sm)
 {
     LastPlayer = null;
     Add(sm);
     InitCards();
     Mix();
 }
Beispiel #2
0
        public void AccceptOpponent()
        {
            int    status = -1;
            Socket s      = tcp.SetUpANewConnection(ref status);

            socketlist2[currentClient] = new SocketModel(s);
        }
Beispiel #3
0
 public void TransData(SocketModel s, string str)
 {
     if (CurrentPlayer.SocketPlayer == s)
     {
         data = str;
     }
 }
Beispiel #4
0
 public void TransData(SocketModel s, string str)
 {
     if (CurrentPlayer == s.GetRemoteEndpoint())
     {
         data = str;
     }
 }
Beispiel #5
0
        public void write(int type, int command, string name, string message)
        {
            SocketModel model     = new SocketModel(type, command, name, message);
            ByteArray   byteArray = new ByteArray();

            byteArray.WriteInt(model.type);
            byteArray.WriteInt(model.command);
            if (!string.IsNullOrEmpty(model.name))
            {
                byte[] bs1 = Encoding.UTF8.GetBytes(model.name);
                byteArray.WriteInt(bs1.Length);
                byteArray.WriteBytes(bs1);
            }
            else
            {
                byteArray.WriteInt(0);
            }
            if (!string.IsNullOrEmpty(model.message))
            {
                byte[] bs2 = Encoding.UTF8.GetBytes(model.message);
                byteArray.WriteInt(bs2.Length);
                byteArray.WriteBytes(bs2);
            }
            else
            {
                byteArray.WriteInt(0);
            }

            socket.Send(byteArray.Buffer);
        }
Beispiel #6
0
 public void Cancel(SocketModel s)
 {
     for (int i = 0; i < players.Count; i++)
     {
         if (players[i].SocketPlayer == s)
         {
             players[i].PlayerStatus = false;
         }
     }
 }
Beispiel #7
0
 //void StartGame1()
 //{
 //    serverbot = new Bot[4 - players.Count];
 //    Playing = true;
 //    int count = 0;
 //    int i = FindFistTurn();
 //    PreviousCard = "|";
 //    Mix();
 //    SendCard();
 //    for(int y=0;y<serverbot.Length;y++)
 //    {
 //        List<Card> temp = new List<Card>();
 //        for (int x = 51 - y * 13; x > 51 - y * 13 - 13; x--)
 //            temp.Add(Cards[x]);
 //     serverbot[y] = new Bot(temp,y.);
 //    }
 //    while(players.Count>0)
 //    {
 //        if(i>=players.Count)
 //        {
 //            if()
 //            serverbot[i-players.Count].
 //        }
 //    }
 //}
 public void SendOtherPlayer(SocketModel s, string str)
 {
     for (int i = 0; i < players.Count; i++)
     {
         if (s != players[i].SocketPlayer)
         {
             players[i].SocketPlayer.SendData("PlayerTurn" + str);
         }
     }
 }
Beispiel #8
0
 //BeginInvoke((Action)(() => CountDownTimer.Start()));
 public void OutRoom(SocketModel s)
 {
     for (int i = 0; i < players.Count; i++)
     {
         if (players[i].SocketPlayer == s)
         {
             players.Remove(players[i]);
         }
     }
 }
Beispiel #9
0
        public void Accept2()
        {
            int    status = -1;
            Socket s      = tcp.SetUpANewConnection(ref status);

            socketList2[currentClient] = new SocketModel(s);
            string str = socketList2[currentClient].GetRemoteEndpoint();

            txbConnectionManager.AppendText("\nNew connection from: " + str + "id" + currentClient + "\n");
        }
Beispiel #10
0
        public void Accept()
        {
            int    status = -1;
            Socket s      = tcp.SetUpANewConnection(ref status);

            socketList[currentClient] = new SocketModel(s);
            string str  = socketList[currentClient].GetRemoteEndpoint();
            string str1 = "New connection from: " + str + "\n";

            textBox3.AppendText(str1);
        }
Beispiel #11
0
        public override void MessageReceive(UserToken token, object message)
        {
            Console.WriteLine("有客户发送消息了");
            SocketModel model = message as SocketModel;

            switch (model.type)
            {
            case Protocol.TYPE_LOGIN:
                login.MessageReceive(token, model);
                break;
            }
        }
Beispiel #12
0
        public void Accept()
        {
            int    status = -1;
            Socket s      = tcp.SetUpANewConnection(ref status);

            socketlist1[currentClient] = new SocketModel(s);

            string st  = socketlist1[currentClient].GetRemoteEndpoint();
            string st1 = "New connect from: " + st;

            Console.WriteLine(st1);
            lbManageConnect.Items.Add(st1);
        }
Beispiel #13
0
 public void process(Session session, SocketModel model)
 {
     try
     {
         if (!AccountManager.Accounts.Contains(session))
         {
             AccountManager.Accounts.Add(session);
         }
     }
     catch (Exception e)
     {
         Log.form.AddText(e.ToString());
     }
 }
Beispiel #14
0
        public SocketModel Accept()
        {
            int         status = -1;
            Socket      s      = tcp.SetUpANewConnection(ref status);
            SocketModel player = new SocketModel(s);
            //Room.Add(player);
            //socketList[currentClient] = new SocketModel(s);
            //string str = socketList[currentClient].GetRemoteEndpoint();
            string str  = player.GetRemoteEndpoint();
            string str1 = "New connection from: " + str + "\n";

            textBox3.AppendText(str1);
            return(player);
        }
Beispiel #15
0
 public int SearchEmtyRoom(SocketModel sm)
 {
     for (int i = 0; i < Room.Count; i++)
     {
         if (Room[i].NumOfPlayer() == 0)
         {
             Room[i].Add(sm);
             Console.WriteLine(i);
             return(i);
         }
     }
     Console.WriteLine(-1);
     return(-1);
 }
Beispiel #16
0
 public int RoomSearching(SocketModel sm)
 {
     for (int i = 0; i < Room.Count; i++)
     {
         if (Room[i].CanJoin())
         {
             Room[i].Add(sm);
             Console.WriteLine(i);
             return(i);
         }
     }
     Console.WriteLine(-1);
     return(-1);
 }
Beispiel #17
0
 public void Add(SocketModel a)
 {
     clients.Add(a); count++;
     if (Check())
     {
         Shuffle();                         //
         currentPlayer = CheckFirst() / 13; //2;////init curr player that have 3.1
         Deal();                            //
         Thread l = new Thread(Play);       //play turn
         l.Start();
         if (done)
         {
             l.Abort(); count = 0; clients.Clear();
         }
     }
 }
Beispiel #18
0
        public void Ready(SocketModel s)
        {
            for (int i = 0; i < players.Count; i++)
            {
                if (players[i].SocketPlayer == s)
                {
                    players[i].PlayerStatus = true;
                }
            }

            if (ReadyToStar())
            {
                Thread t = new Thread(StartGame);
                t.IsBackground = true;
                t.Start();
            }
        }
Beispiel #19
0
        public void process(Session session, SocketModel model)
        {
            try
            {
                switch (model.type)
                {
                case Type.Create:
                    CreateHandler.GetInstance().process(session, model);
                    break;

                case Type.SendMessage:
                    SendMessageHandler.GetInstance().process(session, model);
                    break;

                default:

                    break;
                }
            }
            catch (Exception e)
            {
                Log.form.AddText(e.ToString());
            }
        }
Beispiel #20
0
        public void process(Session session, SocketModel model)
        {
            try
            {
                switch (model.command)
                {
                case Command.GetComments:

                    if (!AccountManager.Comments.ContainsKey(model.name))
                    {
                        session.write(model.type, model.command, model.name, string.Empty);
                    }
                    else
                    {
                        for (int i = 0; i < AccountManager.Comments[model.name].Count; i++)
                        {
                            session.write(model.type, model.command, model.name, AccountManager.Comments[model.name][i]);
                        }
                    }

                    break;

                case Command.SendComment:



                    DataManager.GetInstance().SaveData(model.name, model.message);

                    if (!AccountManager.Comments.ContainsKey(model.name))
                    {
                        DataManager.GetInstance().SaveNameData(model.name);


                        List <string> comments = new List <string>();
                        comments.Add(model.message);
                        AccountManager.Comments.Add(model.name, comments);
                    }
                    else
                    {
                        AccountManager.Comments[model.name].Add(model.message);
                    }



                    foreach (Session s in AccountManager.Accounts)
                    {
                        if (s != session)
                        {
                            s.write(model.type, model.command, model.name, model.message);
                        }
                    }

                    break;

                default:
                    break;
                }
            }
            catch (Exception e)
            {
                Log.form.AddText(e.ToString());
            }
        }
Beispiel #21
0
 public Player(SocketModel s)
 {
     SocketPlayer = s;
     PlayerStatus = false;
 }
Beispiel #22
0
 public void Add(SocketModel s)
 {
     players.Add(new Player(s));
 }
Beispiel #23
0
        public void Commmunication(object obj)
        {
            int         RoomIndex = -1;
            SocketModel sm        = (SocketModel)obj;

            try
            {
                while (sm.IsAlive())
                {
                    string str = sm.ReceiveData();
                    if (str.Length == 0)
                    {
                        sm.CloseSocket();
                        return;
                    }
                    switch (str)
                    {
                    case "Search":
                        RoomIndex = RoomSearching(sm);
                        if (RoomIndex == -1)
                        {
                            RoomIndex = RoomCreate(sm);
                        }
                        if (RoomIndex != -1)
                        {
                            sm.SendData("#RoomFound|" + RoomIndex);
                        }
                        break;

                    case "Ready":
                        if (RoomIndex != -1)
                        {
                            Room[RoomIndex].Ready(sm);
                        }
                        break;

                    case "Cancel":
                        if (RoomIndex != -1)
                        {
                            Room[RoomIndex].Cancel(sm);
                        }
                        break;

                    case "Create":
                        RoomIndex = SearchEmtyRoom(sm);
                        if (RoomIndex == -1)
                        {
                            RoomIndex = RoomCreate(sm);
                        }
                        if (RoomIndex != -1)
                        {
                            sm.SendData("#CreateRoomSuccessful|" + RoomIndex);
                        }
                        break;

                    case "Exit":
                        if (RoomIndex != -1)
                        {
                            Room[RoomIndex].Remote(sm);
                            RoomIndex = -1;
                            sm.SendData("#Exit");
                        }
                        break;

                    default:
                        if (RoomIndex != -1)
                        {
                            Room[RoomIndex].TransData(sm, str);
                        }
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace.ToString());
                sm.CloseSocket();
            }
        }
Beispiel #24
0
 public int RoomCreate(SocketModel sm)
 {
     Room.Add(new Room1(sm));
     return(Room.Count - 1);
 }
Beispiel #25
0
 public Room1(SocketModel sm)
 {
     Add(sm);
     InitCards();
     Mix();
 }