static void Main(string[] args) { Console.WriteLine($"My id is {int.Parse(args[1])}"); CSharpClient client = new CSharpClient(); client.OnReceive += delegate() { IMsg msg = client.Take(); MessageToOneClient mm = msg.Content as MessageToOneClient; Console.WriteLine($"Message type::{msg.PacketType}"); Console.WriteLine(mm); }; Console.WriteLine("Connecting......"); if (client.Connect("127.0.0.1", 7777)) { Console.WriteLine("成功连接Agent."); } else { Console.WriteLine("连接Agent失败."); } MessageToServer mm = new MessageToServer(); mm.PlayerID = int.Parse(args[1]); mm.TeamID = int.Parse(args[0]); mm.JobType = Communication.Proto.JobType.Job1; client.SendMessage(mm); Console.ReadLine(); client.Stop(); client.Dispose(); }
void FixedUpdate() { if (isGameStarted) { GenerateMessage(); if (isNewMessageToServer) { isNewMessageToServer = false; messageToServer.TeamID = teamId; messageToServer.PlayerID = playerId; csharpClient.SendMessage(messageToServer); //Debug.Log("msg send"); } } }
void Start() { Debug.Log("开始初始化参数"); propManager = GetComponent <PropManager>(); heroManager = GetComponent <HeroManager>(); bulletManager = GetComponent <BulletManager>(); Debug.Log(Application.dataPath); string str = File.ReadAllText(Application.streamingAssetsPath + "/JobTest.txt"); /*TextAsset txt = Resources.Load("JobTest") as TextAsset; * string[] s = txt.text.Split(' ');*/ string[] s = str.Split(' '); port = (ushort)float.Parse(s[0]); teamId = (int)float.Parse(s[1]); playerId = (int)float.Parse(s[2]); jobN = (int)float.Parse(s[3]); // TO DO:初始化通信 messageToServer = new MessageToServer(); csharpClient = new CSharpClient(); csharpClient.OnReceive += delegate() { //Debug.Log("Message Received."); if (csharpClient.TryTake(out IMsg iMsg)) { switch (iMsg.PacketType) { case PacketType.MessageToClient: { MessageToClient msg = iMsg.Content as MessageToClient; //Debug.Log("msg received"); switch (msg.MessageType) { case MessageType.StartGame: GameStart(msg); break; case MessageType.Gaming: Refresh(msg); break; case MessageType.EndGame: GameOver(); break; default: break; } break; } case PacketType.MessageToOneClient: { MessageToOneClient msg = iMsg.Content as MessageToOneClient; //Debug.Log("msg received"); switch (msg.MessageType) { case MessageType.ValidPlayer: Debug.Log("Info Valid"); break; case MessageType.InvalidPlayer: Debug.Log("Info Invalid"); break; case MessageType.Send: Debug.Log("Info Send"); break; default: break; } break; } default: break; } } else { Debug.Log("Failed to pop a message"); } }; if (csharpClient.Connect("127.0.0.1", port)) { Debug.Log("成功连接Agent."); } else { Debug.Log("连接Agent失败."); Application.Quit(); } messageToServer.MessageType = MessageType.AddPlayer; messageToServer.TeamID = teamId; messageToServer.PlayerID = playerId; switch (jobN) { case 0: messageToServer.JobType = JobType.Job0; break; case 1: messageToServer.JobType = JobType.Job1; break; case 2: messageToServer.JobType = JobType.Job2; break; case 3: messageToServer.JobType = JobType.Job3; break; case 4: messageToServer.JobType = JobType.Job4; break; case 5: messageToServer.JobType = JobType.Job5; break; case 6: messageToServer.JobType = JobType.Job6; break; } csharpClient.SendMessage(messageToServer); //WebClient heros = new ConcurrentDictionary <long, HeroScript>(); props = new ConcurrentDictionary <long, PropScript>(); bullets = new ConcurrentDictionary <long, BulletScript>(); isCharactersExisted = new ConcurrentDictionary <long, bool>(); isPropsExisted = new ConcurrentDictionary <long, bool>(); isBulletsExisted = new ConcurrentDictionary <long, bool>(); laidList = new ConcurrentDictionary <long, bool>(); TaskQueue = new ConcurrentQueue <KeyValuePair <long, GameObjInfo> >(); LaidQueue = new ConcurrentQueue <GameObjInfo>(); isReady = false; myAngle = 0; isNewMessageToServer = false; for (int i = 0; i < 50; i++) { for (int j = 0; j < 50; j++) { mapColor[i, j] = 0; cellColor[i, j] = 0; } } Debug.Log("参数初始化完成"); }