Difference between revisions of "LÖVE CÖNNECTION (日本語)"

m (チュートリアル)
m (変数・テーブル)
Line 50: Line 50:
  
 
== 変数・テーブル ==
 
== 変数・テーブル ==
* Net.client = table'' --Holds Ip and port of currently connected server, if not connected ip and port are nil''
+
* Net.client = table'' -- 現在接続されているサーバの IPアドレスとポートを保持しており、未接続の場合は IPアドレスとポートは nil となります。''
* Net.server = table'' --Holds the port currently being listened on, nil if not listening''
+
* Net.server = table'' -- ポートが現在接続待機状態であるかを保持しており、接続待機状態でなければ nil となります。''
* Net.commands = table'' --Holds all currently registered commands in format CMD = FUNCTION, command editing function coming soon!''
+
* Net.commands = table'' -- コマンド = 関数の形式で現在登録されている全てのコマンドを保持しています。コマンド編集用の関数は近いうちに公開予定です!''
* Net.users = table'' --Holds all currently connected users in format ID = PLAYERTABLE, player table editing function coming soon!''
+
* Net.users = table'' -- ID = PLAYERTABLE の形式で現在登録されている全ての遊戯者を保持しています。遊戯者テーブル編集用の関数は近いうちに公開予定です!''
 
* Net.maxPing = integer'' -- サーバー、あるいはクライアントにおける現在の最大 Ping 値です。''
 
* Net.maxPing = integer'' -- サーバー、あるいはクライアントにおける現在の最大 Ping 値です。''
* Net.connected = boolean'' --True if connected to a server or listening to a port, false if not''
+
* Net.connected = boolean'' -- サーバへ接続しているかポートが接続待機状態ならば true であり、それ以外は false です。''
 
 
  
 
== チュートリアル ==
 
== チュートリアル ==

Revision as of 06:11, 11 August 2017

O.png このページは翻訳・修正途中です。正式版は機会を見て更新します。  



LÖVE CÖNNECTION は Nicholas Scott (ニコラス・スコット) により開発および保守されているネットワーキング・モジュールです。

require() でモジュールが読み込まれたときに関数一覧テーブルが返されるため、 require で設定されたものは Net~ と等価であると想定します。

関数

  • Net:connectedUsers() -- 現在接続されている利用者の一覧を返します。
  • Net:kickUser( id, reason ) -- 指定された id により利用者を追い出してから現在の画面に理由を表示します。
  • Net:isServer() -- サーバーが現在実行中ならば true を返します。
  • Net:isClient() -- クライアントが現在実行中ならば true を返します。
  • Net:setMaxPing( ping ) -- クライアントに呼び出された場合は再びサーバーへ Ping を送信する前に Ping 時間の設定を行い、サーバー実行中に呼び出された場合はクライアントに対してタイムアウトになる前に最大 Ping (ミリ秒) 値を設定します。
  • Net:init( state ) -- Starts the networking, state needs to be either server, to run as a server, or client, to run as a client
  • Net:update( dt ) -- Add this into any ACTIVE love.update() and pass the deltatime from the love.update!! IMPORTANT!!!!
  • Net:connect( ip, port ) --If called as server you must set ip to nil and port to the port you want to listen on, defaults to 20024, when called as client ip and port are required, and port msut be the same as the servers, obviously :D
  • Net:disconnect() -- クライアントからソケットの出力がすべて nil となったかサーバーに切断パケットが送信されたた場合は、オンラインから切断します。
  • Net:registerCMD( cmd, function ) --Registers a command for networking, cmd is a string name of the command you want to register, and function is the function ran when a client( or server ) receives the command specified. More on this below :D
  • Net:send( table, cmd, param, id ) -- Id is only supplied if running as server, table is a table of data you want to send, cmd is the command your running on the other end, must be registered, param is parameters to the command, id is the id of the client you want to send to( only if server leave nil if client)
  • Net:encode( table ) -- Encodes a table of data into a string to be sent across the network
  • Net:decode( string ) -- Decodes a string into a table of data when received

イベント

These are called the same way you call love.update() function Net.event.server.userConnected( id ) end


クライアント・イベント

  • Net.event.client.connect( ip, port) -- Called when client connects to a server with net:connect() ip is ip of server and port is port of server
  • Net.event.client.receive( table, dt, cmd, param ) -- Called when client receives a packet table is the table client sent, dt deltatime of net:update(), cmd is the command from client, param is parameters from the client
  • Net.event.client.disconnect() --Called when client disconnects from server with net:disconnect()
  • Net.event.client.cmdRegistered( cmd, functionS ) -- Called when a command is registered, cmd is the cmd and function is the function called by the cmd
  • Net.event.client.send( table, cmd, param ) -- Called when a packet is sent to the server, table is the table being sent, cmd is the cmd, param is parameters
  • Net.event.client.kickedFromServer( reason ) -- Called when we( the client ) is kicked from the server, reason is the reason for the kick


サーバー・イベント

  • Net.event.server.userConnected( id ) -- 利用者がサーバーへ接続する時に呼び出されます。
  • Net.event.server.userDisconnected( id ) -- 利用者がサーバーから切断された時に呼び出されます。
  • Net.event.server.userTimedOut( id ) -- 利用者がサーバーからタイムアウトになった時に呼び出されます。
  • Net.event.server.userKicked( id, reason ) --Called when a user is kicked, reason is the reason they were kicked
  • Net.event.server.receive( table, dt, id, cmd, param ) --Called when we receive a packet, table is the table sent by client, id is id of client, dt is deltatime of net:update(), cmd is the command sent by client, param is parameters of the client
  • Net.event.server.connect( port ) --Called when we connect to a port, port is the port connected to
  • Net.event.server.disconnect() --Called when we disconnect from the port and stop listening to packets
  • Net.event.server.cmdRegistered( cmd, functionS) --Called when we register a command, cmd is the command registered, function is the function called by the cmd
  • Net.event.server.send( table, cmd, param, id ) --Called when we send a packet to a client, table is the table sent, cmd is the cmd sent, param is the parameters sent, id is the id of the client we sent to


変数・テーブル

  • Net.client = table -- 現在接続されているサーバの IPアドレスとポートを保持しており、未接続の場合は IPアドレスとポートは nil となります。
  • Net.server = table -- ポートが現在接続待機状態であるかを保持しており、接続待機状態でなければ nil となります。
  • Net.commands = table -- コマンド = 関数の形式で現在登録されている全てのコマンドを保持しています。コマンド編集用の関数は近いうちに公開予定です!
  • Net.users = table -- ID = PLAYERTABLE の形式で現在登録されている全ての遊戯者を保持しています。遊戯者テーブル編集用の関数は近いうちに公開予定です!
  • Net.maxPing = integer -- サーバー、あるいはクライアントにおける現在の最大 Ping 値です。
  • Net.connected = boolean -- サーバへ接続しているかポートが接続待機状態ならば true であり、それ以外は false です。

チュートリアル

サーバーの設定

その 1: モジュールを変数として定義します。

Net = require( "net" )

その 2: ネットワークを初期化します。

Net:init( "Server" )

その 3: パケットの受信待機をするためにポートへ接続します。

Net:connect( nil, 25045 )

その 4: 受信されたパケットに対してあるコマンドの登録を行います。 table は利用者によりエンコードされ、送信されたテーブルです。 :D このようにすると便利です

Net:registerCMD( "updateStatsOfPlayer", function( table, parameters, id, dt ) Net.users[id].name = table.name Net.users[id].color = table.color end )

その 5: クライアントへあるパケットを送信します! :D これはサーバのコンソールから各クライアントへ "Hello There Mr. Client!" を表示します。

for id,playerdata in pairs( Net.users ) do Net:send( {}, "print", "Hello There Mr. Client!", id ) end


クライアントの設定

その 1: モジュールを変数として定義します。

Net = require( "net" )

その 2: ネットワークを初期化します。

Net:init( "Client" )

その 3: サーバへの接続を行います。これは接続機能の初期化も行い net:send() を使用可能にします。

Net:connect( "127.0.0.1", 25045 )

その 4: 受信されたパケットに対してあるコマンドの登録を行います。 table は利用者によりエンコードされ、送信されたテーブルです。 :D このようにすると便利です

Net:registerCMD( "updateStatsOfBattlefield", function( table, parameters, id, dt )Tank.x = table.x Tank.y = table.y Tank.name = table.name end )

その 5: サーバへあるパケットを送信します! :D これはサーバのコンソールへ "Hello There Mr. Server!" を表示します。 {} は空のテーブルですが、 NIL は必要なものであり除去してはいけません。

Net:send( {}, "print", "Hello There Mr. Server!" )

そのほかの言語