protected void Packet_UloadAvatar(long connectionId, byte[] data) { ByteBuffer buffer = new ByteBuffer(); buffer.WriteBytes(data); //Skip packet id buffer.ReadLong(); //Read image bytes byte[] imageBytes = buffer.ReadBytes(buffer.Length()); // upload var urlPath = AvatarsManager.UploadAvatar(connectionId, imageBytes); // send to player OK message ServerSendPackets.Send_UpdateUserAvatar(connectionId, connectionId, urlPath); }
protected void Packet_Authorize(long connectionId, byte[] data) { ByteBuffer buffer = new ByteBuffer(); buffer.WriteBytes(data); //skip packet id buffer.ReadLong(); string token = buffer.ReadString(); if (int.TryParse(token, out int tokenHash)) { AuthService.AuthorizeClientOnGameServer(connectionId, tokenHash); } else { ServerSendPackets.Send_ErrorBadAuthToken(connectionId); } }
/// <summary> /// Called by HandleData /// Proceeds data by calling Packet_MethodName methods /// </summary> private void HandleDataPackets(long connectionId, byte[] data) { //Add our data to buffer ByteBuffer buffer = new ByteBuffer(); buffer.WriteBytes(data); //Read out a packet id long packetId = buffer.ReadLong(); //Delete buffer from memory buffer.Dispose(); //Try find function tied to this packet id if (packets.TryGetValue(packetId, out Packet packet)) { //Log packet id Client client = ClientManager.GetConnectedClient(connectionId); Log.WriteLine($"{client} sent {(ClientPacketId) data[0]}", typeof(PacketHandlerTransportLayer)); //check if client is authorized if (!client.Authorized) { // if he doenst sent authorize this time if ((ClientPacketId)data[0] != ClientPacketId.Authorize) { ServerSendPackets.Send_ErrorBadAuthToken(connectionId); } } // else if was authorized ok { //Call method tied to a Packet by InitPackets() method packet.Invoke(connectionId, data); } } else { Log.WriteLine("Wrong packet: " + packetId, typeof(PacketHandlerTransportLayer)); } }