void OnClientReady(ClientReady ready, Connection conn) { if (conn.state == ConnState.WaitForReady) { conn.state = ConnState.InGame; Player p = lm.AddPlayer(ControllerType.Remote, NewPlayerId(), conn.playerName); conn.playerId = p.id; //发送游戏状态 InitServerGameInfo info = new InitServerGameInfo(); //此客户端的玩家信息 info.clientLocalPlayer = p.AchievePlayerInfo(); //其他玩家的信息 info.elsePlayers = new PlayerInfo[lm.playerCount - 1]; lm.AchievePlayerInfo(info.elsePlayers, p.id); Server.SendMessage(new GameMsg(GameMsg.MsgType.InitServerGameInfo, info), conn.connId, UnityEngine.Networking.QosType.ReliableSequenced); //通知其他玩家 PlayerJoin join = new PlayerJoin(); join.info = info.clientLocalPlayer; GameMsg msg = new GameMsg(GameMsg.MsgType.PlayerJoin, join); SendToAllClientsInGame(msg, conn.connId, UnityEngine.Networking.QosType.ReliableSequenced); } }
private void ClientReady(Message packet) { ((Network.Connection)packet.connection).decryptIncoming = (__Null)1; using (ClientReady clientReady = ClientReady.Deserialize((Stream)packet.get_read())) { using (List <ClientReady.ClientInfo> .Enumerator enumerator = ((List <ClientReady.ClientInfo>)clientReady.clientInfo).GetEnumerator()) { while (enumerator.MoveNext()) { ClientReady.ClientInfo current = enumerator.Current; ((Network.Connection.ClientInfo)((Network.Connection)packet.connection).info).Set((string)current.name, (string)current.value); } } this.connectionQueue.JoinedGame((Network.Connection)packet.connection); Interface.CallHook("OnPlayerConnected", (object)packet); using (TimeWarning.New(nameof(ClientReady), 0.1f)) { using (TimeWarning.New("SpawnPlayerSleeping", 0.1f)) { if (this.SpawnPlayerSleeping((Network.Connection)packet.connection)) { return; } } using (TimeWarning.New("SpawnNewPlayer", 0.1f)) this.SpawnNewPlayer((Network.Connection)packet.connection); } } }
private void ClientReady(Message packet) { packet.connection.decryptIncoming = true; using (ClientReady clientReady = ClientReady.Deserialize(packet.read)) { foreach (ClientReady.ClientInfo clientInfo in clientReady.clientInfo) { packet.connection.info.Set(clientInfo.name, clientInfo.@value); } this.connectionQueue.JoinedGame(packet.connection); Interface.CallHook("OnPlayerConnected", packet); using (TimeWarning timeWarning = TimeWarning.New("ClientReady", 0.1f)) { using (TimeWarning timeWarning1 = TimeWarning.New("SpawnPlayerSleeping", 0.1f)) { if (this.SpawnPlayerSleeping(packet.connection)) { return; } } using (timeWarning1 = TimeWarning.New("SpawnNewPlayer", 0.1f)) { this.SpawnNewPlayer(packet.connection); } } } }
public void ChangeClientState(ClientConnectionState state) { if (CurrentState != state && state == ClientConnectionState.READY) { ClientReady?.Invoke(this, EventArgs.Empty); } CurrentState = state; Console.WriteLine($"Client {ToString()} state changed to ({state.ToString()})"); }
internal SpotifyAuthentication() { bool initialized = false; var client_id = "7b2f38e47869431caeda389929a1908e"; var secret_id = "c3a86330ef844c16be6cb46d5e285a45"; _authenFactory = new AuthorizationCodeAuth( client_id, secret_id, "http://localhost:8800", "http://localhost:8800", Scope.UserReadCurrentlyPlaying | Scope.UserModifyPlaybackState | Scope.AppRemoteControl | Scope.UserReadPlaybackState ); _authenFactory.AuthReceived += async(s, p) => { var ath = (AuthorizationCodeAuth)s; ath.Stop(); var token = await ath.ExchangeCode(p.Code); _refreshToken = token.RefreshToken; if (_client == null) { _client = new SpotifyWebAPI() { AccessToken = token.AccessToken, TokenType = "Bearer" }; } else { _client.AccessToken = token.AccessToken; } if (!initialized) { ClientReady?.Invoke(this, _client); } initialized = true; }; _authenFactory.Start(); _authenFactory.OpenBrowser(); _refreshTokenWorker = new Timer(); _refreshTokenWorker.Interval = 30 * (1000 * 60); _refreshTokenWorker.Elapsed += async(s, e) => { var token = await _authenFactory.RefreshToken(_refreshToken); _client.AccessToken = token.AccessToken; }; _refreshTokenWorker.Start(); }
void OnLoadingDone() { if (loadingTask == LoadingTask.Nothing) { txtTips.text = "加载完成"; asyncOperation.allowSceneActivation = true; } else if (loadingTask == LoadingTask.SwitchGameScene) { txtTips.text = "加载完成"; ClientReady ready = new ClientReady(); Client.SendMessage(new GameMsg(GameMsg.MsgType.ClientReady, ready), UnityEngine.Networking.QosType.ReliableSequenced); } }
protected override Response OnReceive(SimpleMessagePurport message) { switch (message) { case SimpleMessagePurport.ClientIsReady: ClientReady?.Invoke(); return(new SimpleResponse(SimpleResponsePurport.Acknowledged)); case SimpleMessagePurport.ConfigurationNeeded: return(HandleConfigurationRequest()); case SimpleMessagePurport.RequestShutdown: ShutdownRequested?.Invoke(); return(new SimpleResponse(SimpleResponsePurport.Acknowledged)); } return(new SimpleResponse(SimpleResponsePurport.UnknownMessage)); }
public void FireClientReady(Client client) { ClientReady?.Invoke(client); }
void OnDateEvent(GameMsg msg, int connId) { if (connDict.ContainsKey(connId)) { Connection conn = connDict[connId]; if (conn == null) { //不应该发生 Debug.LogError("ServerAgent.OnDateEvent>> connection is null"); return; } // 设置conn的lastTime conn.lastRecvTime = DateTime.Now; if (msg.type == GameMsg.MsgType.JoinGameReq) { JoinGameReq req = msg.content as JoinGameReq; if (req != null) { OnJoinGameReq(req, conn); } } else if (msg.type == GameMsg.MsgType.ClientReady) { ClientReady ready = msg.content as ClientReady; if (ready != null) { OnClientReady(ready, conn); } } else if (msg.type == GameMsg.MsgType.QuitGameReq) { QuitGameReq quit = msg.content as QuitGameReq; if (quit != null) { OnClientQuit(quit, conn); } } else if (msg.type == GameMsg.MsgType.ClientLocalPlayerInfo) { ClientLocalPlayerInfo state = msg.content as ClientLocalPlayerInfo; if (state != null) { OnClientLocalState(state, conn); } } else if (msg.type == GameMsg.MsgType.Damage) { HitPlayer hit = msg.content as HitPlayer; if (hit != null) { OnDamage(hit, conn); } } else if (msg.type == GameMsg.MsgType.Shoot) { PlayerShoot shoot = msg.content as PlayerShoot; if (shoot != null) { OnShoot(shoot, conn); } } } }
private Task ClientReadyEvent() { ClientReady?.Invoke(this, EventArgs.Empty); return(Task.CompletedTask); }
private void HandlePacket(byte type, byte[] payload) { List <byte> payloadList = new List <byte>(payload); switch (type) { case (byte)SCPackets.QUERY: if ((int)CurrentState % 8 == 0) { break; } int nameLength = payloadList.GetNextInt(); string name = Encoding.Unicode.GetString(payloadList.GetBytes(nameLength)); int maxOnline = payloadList.GetNextInt(); int online = payloadList.GetNextInt(); CurrentServer.Name = name; CurrentServer.MaxOnline = maxOnline; CurrentServer.Online = online; CurrentServer.Status = ServerStatus.ONLINE; ServerQueryReceived?.Invoke(this, new ServerQueryReceivedEventArgs() { Server = CurrentServer, Client = this }); break; case (byte)SCPackets.MESSAGE: if (CurrentState != ClientConnectionState.READY) { break; } bool broadcast = BitConverter.ToBoolean(payloadList.GetByteInByteCollection().CheckEndianness(), 0); int authorLength = payloadList.GetNextInt(); string author = Encoding.Unicode.GetString(payloadList.GetBytes(authorLength)); int messageLength = payloadList.GetNextInt(); string message = Encoding.Unicode.GetString(payloadList.GetBytes(messageLength)); SendMessage( (broadcast) ? MessageType.BROADCAST : MessageType.CHAT, message, author); break; case (byte)SCPackets.READY: if (CurrentState != ClientConnectionState.CONNECTED) { break; } CurrentState = ClientConnectionState.READY; ClientReady?.Invoke(this, EventArgs.Empty); break; case (byte)SCPackets.NOTIFICATION: if (CurrentState != ClientConnectionState.READY) { break; } MessageBoxIcon[] iconMap = new MessageBoxIcon[] { MessageBoxIcon.None, MessageBoxIcon.Information, MessageBoxIcon.Warning, MessageBoxIcon.Error, }; int level = payloadList.GetNextInt(); int contentLength = payloadList.GetNextInt(); string content = Encoding.Unicode.GetString(payloadList.GetBytes(contentLength)); if (level > 4) // invalid level { break; } SendMessage(new MessageEventArgs() { Content = content, Type = MessageType.NOTIFICATION, NotificationIcon = iconMap[level], Client = this, }); break; case (byte)SCPackets.DISCONNECT: Disconnect(false, "Server closed connection."); break; default: break; } }