Пример #1
0
		public static void OnRoomEvent(this GameServer server, StoSMessage msg, RoomInfo info){
			using(PacketWriter writer = new PacketWriter(2)){
				writer.Write((ushort)msg);
				//length
				writer.Write((ushort)1);
				writer.WriteUnicode(info.Name, 20);
				writer.WriteUnicode(info.Pwd, 20);
				writer.Write((byte)info.Rule);
				writer.Write((byte)info.Mode);
				writer.Write(info.IsStart);
				writer.WriteUnicode(info.Lflist, 60);
				writer.Write(info.Warring);
				writer.Write(info.StartLP);
				writer.Write((ushort)info.players.Length);
				for(int i =0; i<info.players.Length;i++){
					writer.WriteUnicode(info.players[i], 20);
				}
				writer.Write((ushort)info.observers.Count);
				for(int i =0; i<info.observers.Count;i++){
					writer.WriteUnicode(info.observers[i], 20);
				}
				//string str = Tool.ToJson(info);
				//byte[] bs = Encoding.Unicode.GetBytes(str);
				//writer.Write(bs);
				writer.Use();
				//Send(server.LocalClient, writer.Content);
			}
		}
Пример #2
0
		private void Init(RoomInfo room){
			this.Size=new Size(186, 200);
			if(room!=null){
				this.SuspendLayout();
				Label label = new Label();
				
				label.TextAlign = ContentAlignment.MiddleCenter;
				label.Size = new Size(182, 30);
				//label.Location = new Point(3,3);
				label.ForeColor = Color.White;

				if(room.Warring){
					label.BackColor=Color.FromArgb(0xee, 0xdd, 0, 0);
					label.Text = "[有坑]"+room.Name;
				}else{
					if(room.NeedPass()){
						//label.BackColor=Color.FromArgb(0xdd, 0, 0x68, 0x8b);
						label.BackColor=Color.FromArgb(0xee, 0xee, 0xad, 0x0e);
						label.Text = room.Name;
					}else{
						label.BackColor=Color.FromArgb(0xdd, 0, 0x64, 0);
						label.Text = room.Name;
					}
				}
				if(room.IsStart){
					label.Text+=" 【决斗中】";
				}else{
					label.Text+=" 【等待中】";
				}
				this.Controls.Add(label);
				
				Label label2 = new Label();
				label2.Text = "禁限卡表:"+room.Lflist;
				label2.TextAlign = ContentAlignment.MiddleLeft;
				label2.Padding = new Padding(8, 2, 2, 2);
				label2.Size = new Size(182, 26);
				this.Controls.Add(label2);
				
				Label label3 = new Label();
				label3.Text = "允许卡片:"+(room.Rule==0?"OCG":(room.Rule==1?"TCG":"OCG&TCG"));
				label3.TextAlign = ContentAlignment.MiddleLeft;
				label3.Padding = new Padding(8, 2, 2, 2);
				label3.Size = new Size(182, 26);
				this.Controls.Add(label3);
				
				Label label4 = new Label();
				label4.Text = "决斗模式:"+(room.Mode==2?"双打模式":(room.Mode==1?"比赛模式":"单局模式"));
				label4.TextAlign = ContentAlignment.MiddleLeft;
				label4.Padding = new Padding(8, 2, 2, 2);
				label4.Size = new Size(182, 26);
				this.Controls.Add(label4);
				
				Label label5 = new Label();
				label5.Text = "玩家1:"+((room.players!=null && room.players.Length>0)?room.players[0]:"--");
				label5.TextAlign = ContentAlignment.MiddleLeft;
				label5.Padding = new Padding(8, 2, 2, 2);
				label5.Size = new Size(182, 26);
				this.Controls.Add(label5);
				
				if(room.Mode==2){
					Label label7 = new Label();
					label7.Text = "玩家2:"+((room.players!=null && room.players.Length>2)?room.players[2]:"--");
					label7.TextAlign = ContentAlignment.MiddleLeft;
					label7.Padding = new Padding(8, 2, 2, 2);
					label7.Size = new Size(182, 26);
					this.Controls.Add(label7);
				}else{
					Label label6 = new Label();
					label6.Text = "玩家2:"+((room.players!=null && room.players.Length>1)?room.players[1]:"--");
					label6.TextAlign = ContentAlignment.MiddleLeft;
					label6.Padding = new Padding(8, 2, 2, 2);
					label6.Size = new Size(182, 26);
					this.Controls.Add(label6);
					
				}
				
				Button join=new Button();
				join.FlatStyle = FlatStyle.Popup;
				join.Size=new Size(180, 32);
				if(room.NeedPass()){
					join.Text="输入密码";
					join.ForeColor =Color.DarkRed;
					join.BackColor = Color.Gray;
				}else{
					join.Text="加入房间";
				}
				join.Click += new EventHandler(join_Click);
				join.BackColor= SystemColors.Control;
				this.Controls.Add(join);
				this.ResumeLayout(true);
			}
			this.BackColor = Color.White;
		}
Пример #3
0
		public RoomBlock(Client client, Server server,RoomInfo room):base(){
			this.m_room=room;
			this.m_client=client;
			this.m_server=server;
			Init(room);
		}
Пример #4
0
		public void AddRoom(Client client, Server server,RoomInfo room, bool isLast){
			RoomBlock block=new RoomBlock(client,server,room);
			this.Controls.Add(block);
			if(isLast){
				this.ResumeLayout(true);
			}
		}
Пример #5
0
		private void AddRooms(Client client, Server server,RoomInfo[] rooms){
			this.SuspendLayout();
			this.Controls.Clear();
			int i=0;
			//MessageBox.Show("共有"+rooms.Length+"房间");
			foreach(RoomInfo room in rooms){
				i++;
				AddRoom(client,server,room, i==rooms.Length);
			}
			if(rooms.Length==0){
				this.ResumeLayout(false);
			}
		}
Пример #6
0
		public void SetRooms(Client client, Server server,RoomInfo[] rooms){
			if(rooms==null){
				rooms=new RoomInfo[0];
			}
			if (!this.InvokeRequired)
			{
				AddRooms(client,server,rooms);
			}
			else
			{
				BeginInvoke(new Action(()=>{
				                       	AddRooms(client,server,rooms);
				                       })
				           );
			}
		}
Пример #7
0
		public static RoomInfo GetRoomInfo(Game game){
			if(game!=null&&game.Config!=null){
				RoomInfo info=new RoomInfo();
				info.RoomName=game.Config.Name;
				int i=info.RoomName.LastIndexOf("$");
				if(i>=0){
					info.RoomName=info.RoomName.Substring(0, i);
					info.NeedPass =true;
				}else{
					info.NeedPass =false;
				}
				info.StartLP=game.Config.StartLp;
				info.Warring=game.Config.EnablePriority|game.Config.NoCheckDeck|game.Config.NoShuffleDeck;
				info.Rule=game.Config.Rule;
				info.Mode=game.Config.Mode;
				info.Lflist=game.Config.LfList;
				info.IsStart= (game.State!=GameState.Lobby);
				if(game.Players!=null){
					int len=game.Players.Length;
					Player[] pls=new Player[len];
					info.players=new string[len];
					game.Players.CopyTo(pls, 0);
					for(i=0;i<len;i++){
						if(pls[i]!=null){
							info.players[i]=pls[i].Name;
							info.Count++;
						}else{
							info.players[i]="";
						}
					}
				}
				if(game.Observers!=null){
					Player[] pls=game.Observers.ToArray();
					int len=pls.Length;
					info.observers=new string[len];
					for(i=0;i<len;i++){
						if(pls[i]!=null){
							info.observers[i]=pls[i].Name;
						}else{
							info.observers[i]="";
						}
					}
					info.Count+=len;
				}
				return info;
			}
			return null;
		}